trying to find repeated substrings with regular expression
Robert Dodier
robert.dodier at gmail.com
Mon Mar 13 13:00:18 EST 2006
Hello all,
I'm trying to find substrings that look like 'FOO blah blah blah'
in a string. For example give 'blah FOO blah1a blah1b FOO blah2
FOO blah3a blah3b blah3b' I want to get three substrings,
'FOO blah1a blah1b', 'FOO blah2', and 'FOO blah3a blah3b blah3b'.
I've tried numerous variations on '.*(FOO((?!FOO).)*)+.*'
and everything I've tried either matches too much or too little.
I've decided it's easier for me just to search for FOO, and then
break up the string based on the locations of FOO.
But I'd like to better understand regular expressions.
Can someone suggest a regular expression which will return
groups corresponding to the FOO substrings above?
Thanks for any insights, I appreciate it a lot.
Robert Dodier
More information about the Python-list
mailing list