[Tutor] stopping greedy matches
Kent Johnson
kent37 at tds.net
Thu Mar 17 05:32:04 CET 2005
Mike Hall wrote:
> Liam, "re.compile("in (.*?)\b")" will not find any match in the example
> string I provided. I have had little luck with these non-greedy matchers.
"in (.*?)\b" will match against "in " because you use .* which will match an empty string. Try "in
(.+?)\b" (or "(?<=\bin)..+?\b" )to require one character after the space.
The non-greedy match is very useful, if you can't get it to work ask for help.
> I don't appear to have redemo.py on my system (on OSX), as an import
> returns an error. I will look into finding this module, thanks for
> pointing me towards it :)
You can't import it, you have to run it from the command line. I don't know if it is installed under
Mac OSX though. You might be interested in RegexPlor:
http://python.net/~gherman/RegexPlor.html
Kent
More information about the Tutor
mailing list