python - Non-greedy mode in re.search() does not match to end of string -
i'm trying parse values of cookie this:
import re m = re.search("(.*?)=(.*?); path=(.*?); domain=(.*?)", "name=value1; path=/; domain=my.domain.com") print (m.group(0))
result this:
name=value1; path=/; domain=
my question is: why not match @ last non-greedy position? expected result be:
name=value1; path=/; domain=my.domain.com
of course, change greedy mode or use end of line character ($
) i'd understand why it's not working expected work :)
non-greedy means match little can while still allowing entire match succeed. *
means "zero or more". least can match zero. matches 0 , match succeeds.
the other occurrences of .*?
in regex cannot match zero, because entire regex fail match.
Comments
Post a Comment