Quantcast
Channel: Regex atomic grouping does not seem to work in preg_match_all() - Stack Overflow
Viewing all articles
Browse latest Browse all 2

Regex atomic grouping does not seem to work in preg_match_all()

$
0
0

I've recently been playing with regular expressions, and one thing doesn't work as expected for me when I use preg_match_all in php.

I'm using an online regex tool at http://www.solmetra.com/scripts/regex/index.php.

The regex I'm using is /(?>x|y|z)w/. I'm making it match abyxw. I am expecting it to fail, yet it succeeds, and matches xw.

I am expecting it to fail, due to the use of atomic grouping, which, from what I have read from multiple sources, prevents backtracking. What I am expecting precisely is that the engine attempts to match the y with alternation and succeeds. Later it attempts to match w with the regex literal w and fails, because it encounters x. Then it would normally backtrack, but it shouldn't in this case, due to the atomic grouping. So from what I know it should keep trying to match y with this atomic group. Yet it does not.

I would appreciate any light shed on this situation. :)


Viewing all articles
Browse latest Browse all 2

Latest Images

Trending Articles





Latest Images