正则表达式帮助 - 分隔符

时间:2015-07-13 18:11:01

标签: python regex

- Dropbox login fix
- Updated iris viewer
* other aspects are to be improved
+ fix crash on viewing update 
? Photos in notes now support copy, cut and paste - By long pressing a photo in a note, you can access the context
menu for copy, cut and paste of the photo. The photo can be pasted to any place in the text of notes.
Do you like the version? Please take the time to leave a review whenever you update the app.

我需要使用分隔符( - ,*,+和我在下面使用的其他一些代码)检索句子。所以寻找输出如:

['Dropbox login fix', 'Updated iris viewer', 'other aspects are to be improved', 'fix crash on viewing update', Photos in notes now support copy, cut and paste - By long pressing a photo in a note, you can access the context menu for copy, cut and paste of the photo. The photo can be pasted to any place in the text of notes.']

使用正则表达式:

r = re.split(r'(?m)\s*^[-*:;+&.?]+\s*|\.$',txt)

但这也会返回我不想要的最后一行。这种没有分隔符的自由文本可能/可能不会出现在我正在使用的文本中。

1 个答案:

答案 0 :(得分:2)

请勿使用split。使用此正则表达式:

^\s*[-*:;+&.?]+\s*(.+)$

re.findall()函数中获取所有匹配项。

RegEx Demo