newdev14
newdev14

Reputation: 1111

regex help - delimiters

- 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.

I need to retrieve the sentences with the delimiters (-, *, + and some others that I use below). So looking for output like:

['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.']

Using a regex like:

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

but this also returns the last line, which I don't want. This sort of free text without delimiter may/may not be present in the text I am working with.

Upvotes: 1

Views: 58

Answers (1)

anubhava
anubhava

Reputation: 786339

Don't use split for this. Use this regex:

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

in re.findall() function to get all your matches.

RegEx Demo

Upvotes: 2

Related Questions