Given is the following python script:
text = '<?xml version="1.24" encoding="utf-8">'
mu = (".??[?]?[?]", "....")
for item in mu:
print item,":",re.search(item, text).group()
Can someone please explain why the first hit with the regex .??[?]?[?]
returns <?
instead of just ?
.
My explaination:
.??
should match nothing as .?
can match or not any char and the second ?
makes it not greedy.
[?]?
can match ?
or not, so nothing is good, too
[?]
just matches ?
That should result in ?
and not in <?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…