Regexp optimization question
Bengt Richter
bokr at oz.net
Tue Apr 27 16:09:42 EDT 2004
On Fri, 23 Apr 2004 22:56:38 +0000 (UTC), mlh at furu.idi.ntnu.no (Magnus Lie Hetland) wrote:
>In article <c6brgc$a70l0$1 at ID-99293.news.uni-berlin.de>, William Park wrote:
>[snip]
>>
>>Since you want both the matched strings and their locations in file, you
>>pretty much have to this manually, one by one.
>
>Well -- that's more or less what I'm doing. (Or -- I can get the match
>objects all at once, of course, using finditer.)
>
>I guess I'll have to look elsewhere for performance improvements. Hm.
>
Have you tried something like this?
>>> s = 'asdad foobaz rhubarb pie'
>>> import re
>>> rxo = re.compile(r'(foo|bar|baz)')
>>> rxo.split(s)[1::2]
['foo', 'baz', 'bar']
Regards,
Bengt Richter
More information about the Python-list
mailing list