Python's RE
Jerome Quelin
jerome.quelin at insalien.org
Mon Jun 5 14:27:34 EDT 2000
Evgeny Zemlerub <oblom at barak-online.net> wrote:
>How exectly do I something that reassembles perl's :
>$string = "qwerwe kkljlksdfg (first string) asdkjflkjg
>(secondstring)jlskjlfdkg(one more string)";
>@words = ($string =~ /\((.+?)\)/smg);
>foreach(@words){
> print "$_\n";
>}
Python does not support non-greedy quantifiers (ie, *?, +? and {,}?)... In
fact, Perl is the only language that does, I think. You are to do it another
way in Python.
> print re.search(r'\((.+?)\)',
>'aaa(foo)bbb(bar)asdfsadf',re.S|re.M).groups()
Replace the (.+?) part of your regexp with ([^)]+) and it should work the way I
think you want it to work
Jerome
--
jerome.quelin at insalien.org
More information about the Python-list
mailing list