Re: [Tutor] non-greedy matching

2009-01-30 Thread Willi Richert
Hi, you make it non-greedy with "?": import re text="axa axa" greedy_x, greedy_y = re.match("a.*a", text).span() print text[greedy_x:greedy_y] non_greedy_x, non_greedy_y = re.match("a.*?a", text).span() print text[non_greedy_x:non_greedy_y] Will print out: axa axa axa Regards, wr On Freitag,

Re: [Tutor] non-greedy matching

2009-01-30 Thread A.T.Hofkamp
spir wrote: Hello, imagine you need to match such a pattern: pat : (@@ [charset]* @@) | [charset]* ... where [charset] has to include '@' My questions are: * Is there any other way than using a non-greedy form of [charset]* ? Something like this? (in pseudo-RE syntax) "(@@" ( [...@]* "@" [.

[Tutor] non-greedy matching

2009-01-30 Thread spir
Hello, imagine you need to match such a pattern: pat : (@@ [charset]* @@) | [charset]* ... where [charset] has to include '@' My questions are: * Is there any other way than using a non-greedy form of [charset]* ? * How, actually, is non-greedy character string matching performed? Thank you, de