in reply to Tell or determine whichever Perl regex group fails

Take a look at Regexp::Debugger. I've been using this module for about a decade and can highly recommend it.

"How to surely determine whichever Perl regex group fail ..."

It doesn't really work like that. Assuming you've installed Regexp::Debugger, you can run

$ rxrx -e 'q{okoK} =~ /(o|k)(k|i)(O|K)(K)/'

and watch:

  1. 1st group (o|k) match success on 1st alternative ($1 = "o")
  2. 2nd group (k|i) match success on 1st alternative ($2 = "k")
  3. 3rd group (O|K) match fail
  4. BACKTRACK
  5. 2nd group (k|i) match fail on 2nd alternative ($2 removed)
  6. BACKTRACK
  7. 1st group (o|k) match fail on 2nd alternative ($1 removed)
  8. ... Regex failed to match after 66 steps ...

So, as you can see, capture groups can potentially both succeed and fail at different points in the matching process.

— Ken