regex - PCRE "or" operator behavior? -


if have 1) /foo|oo/ 2) /oo|foo/ , using pcre , match against string "foo" expected result is

  1. 1) foo 2) oo. pcre keeps "or" order.
  2. foo. pcre tries variants , goes longest match.
  3. there no preset rule, optimizer might reorder sees fit. duty of developer avoid ambiguous scenarios this.
  4. 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

Popular posts from this blog

Delphi XE2 Indy10 udp client-server interchange using SendBuffer-ReceiveBuffer -

Qt ActiveX WMI QAxBase::dynamicCallHelper: ItemIndex(int): No such property in -

Enable autocomplete or intellisense in Atom editor for PHP -