python - How is the order of a re.search determined? -
assuming have pattern resembling:
re.compile(r"(pattern1)|(pattern2)|...|(patternn)")
where patterns intentionally ordered method. expected search order left right returning first match, results have proven otherwise.
how order of pattern search determined?
edit: may issue regex since quite lengthy want make sure assumption search method correct.
the search order left right on searched string; left right on pattern same initial position in searched string. thus, if looking r"b|c"
in "dcba"
, "c"
found first, since closest start of "dcba"
"b"
.
but, if looking r"..a|.b"
, "cba"
found rather "cb"
start @ same position, ..a
alternative sooner in pattern.
Comments
Post a Comment