Keep the TRUE non-greedy match using Perl regex -
from following word "tacacatac", want match "cat". seems regex c.*?t should give me this, guess starts first occurrence of "c" , there finds next "t", , thus, matches "cacat".
is there way (perhaps using negative lookahead) start looking c before final t?
-----edit----- need option work if replace letters strings
thanks.
try this:
my $str = "the cat in cat in hat"; if ($str =~ /(cat(?:(?!cat).)*hat)/) { print $1, "\n"; }
Comments
Post a Comment