use strict;
my $str = 'bar //true
,bar, //true
,,bar,, //true
barbar //true
,bar,bar, //true
,,bar,,bar,, //true
barbarbar //true
,bar,bar,bar, //true
,,bar,,bar,,bar,, //true
foo //false
,foo, //false
,,foo,, //false
foobar //false
,foo,bar, //false
,,foo,,bar,, //false
barfoo //false
,bar,foo, //false
,,bar,,foo,, //false
foofoo //false
,foo,foo, //false
,,foo,,foo,, //false
foobarbar //false
,foo,bar,bar, //false
,,foo,,bar,,bar,, //false
barfoobar //false
,bar,foo,bar, //false
,,bar,,foo,,bar,, //false
barbarfoo //false
,bar,bar,foo, //false
,,bar,,bar,,foo,, //false
barfoofoo //false
,bar,foo,foo, //false
,,bar,,foo,,foo,, //false
foobarfoo //false
,foo,bar,foo, //false
,,foo,,bar,,foo,, //false
foofoobar //false
,foo,foo,bar, //false
,,foo,,foo,,bar,, //false
foofoofoo //false
,foo,foo,foo, //false
,,foo,,foo,,foo,, //false';
my $regex = qr/(?<!foo.{0,1000})bar(?!.*foo)/mp;
if ( $str =~ /$regex/g ) {
print "Whole match is ${^MATCH} and its start/end positions can be obtained via \$-[0] and \$+[0]\n";
# print "Capture Group 1 is $1 and its start/end positions can be obtained via \$-[1] and \$+[1]\n";
# print "Capture Group 2 is $2 ... and so on\n";
}
# ${^POSTMATCH} and ${^PREMATCH} are also available with the use of '/p'
# Named capture groups can be called via $+{name}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Perl, please visit: http://perldoc.perl.org/perlre.html