regex - PCRE "or" operator behavior? -
if have 1) /foo|oo/
2) /oo|foo/
, using pcre , match against string "foo" expected result is
- 1)
foo
2)oo
. pcre keeps "or" order. foo
. pcre tries variants , goes longest match.- there no preset rule, optimizer might reorder sees fit. duty of developer avoid ambiguous scenarios this.
- there rule it's not 2.
"try , see" seems kill 1.) there no way determine between 2-3-4 trial , error.
4) match closest start of string. when multiple matches possible current position, match option matches sooner.
e.g.
banana
matching against /na/
(showing match uppercase): banana
(sooner banana
). against /an|b/
, matches banana
(sooner banana
). against /ba|./
, matches banana
(same position, ba
matches before .
). against /.|ba/
, matches banana
(same position, .
matches before ba
).
Comments
Post a Comment