in reply to negative lookbehind and VERY strange capture
Expanding out your regex it becomes obvious
use strict; use warnings; my $s = '"toto"'; if ($s =~ m[^ (?<!\\)" ( ( (?<=\\)"|[^"] )+ # $2 ) # $1 (?<!\\)" $]x ) { print "It matches!\n"; print $1 . "\n"; print $2 . "\n"; }
You have two nested pairs of capturing parens, the inner pair with a repeat. So the outer pair captures everything matched by the inner repetition, and the inner pair captures the last thing it matches. Hence "toto" and the last character of that "o".
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: negative lookbehind and VERY strange capture
by Denis.Beurive (Initiate) on Sep 18, 2016 at 11:53 UTC |