in reply to Re: Unexpected regular expression match
in thread Unexpected regular expression match

Once one backtracks through (?>PAT), the regex engine is free to try to match PAT at a different location (or maybe even at the same location) if backtracking ended successfully earlier in the pattern.

This causes my proposed solution to fail for "2_34_5".

In theme, this can be fixed by preventing backtracking through the early \d+.

/^\d++ _ \d++ (?:_ \d+)?+ \w+ $/x

One can also solve this without any (?>...) at all by being more precise with the definitions.

/^\d+ _ \d+ (?:_ \d+)? (?![\d_])\w+ $/x