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

Popular posts from this blog

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -