I have created two named capture variables in the regex and the second one doesn\'t seem to return any value while the first one can. I am not sure why..here is the code.
<You probably mean:
my $string = 'test [google] another test [windows]';
if( $string =~ /.*?\[(?<firstBracket>\w+)\].*?\[(?<secondBracket>\w+)\]/i ) {
say $+{firstBracket};
say $+{secondBracket};
}
output
google
windows
or
my $re = qr/.*?\[(?<firstBracket>\w+)\].*?\[(?<secondBracket>\w+)\]/i;
if( $string =~ $re ) {
...
}
with same output...