regex - Regular expressions Perl -
regular expression matches 3 consecutive copies of regular expression foo|bar
. pattern should match foofoofoo
, foobarbar
, barbarbar
if($line!~m/((foo)+|(bar)+){0,3}/){print"no match\n";} else { print "$`"; #print out first part of string print "<$&>"; #highlight matching part print "$'"; #print out rest }
this expression, works, somehow check part string.
for example:
input foo
: highlight foo
input foofdafdafbar
: highlight foo
not bar
i need check if either foo
or bar
exist, want make sure when both exist, both highlight
your regex doesn't make sense, based off describe want. additionally, secondary examples seem contradict want in first part.
perhaps you're looking is?
if ($line =~ m/((?:foo|bar){3})/) {
Comments
Post a Comment