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,
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)
"(@@" ( [...@]* "@" [.
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