What is wrong with my regex?
It's too greedy. Make .* less greedy by adding the ? "lazy" modifier to the * "zero-or-more" quantifier to make it .*? instead.
Update: See Quantifiers in perlre; also see discussions of greedy/lazy matching in perlretut. (Update: See also Quantifiers in regular expressions in Tutorials.)
Update 2: Example:
c:\@Work\Perl\monks\OldChamp>perl -wMstrict -le "my $s = 'keep me ZIP delete this ZAP also keep this ZIP kill too ZAP +keep too'; print qq{'$s'}; ;; (my $t = $s) =~ s{ ZIP .* ZAP }{}xmsg; print qq{greedy .*: '$t'}; ;; ($t = $s) =~ s{ ZIP .*? ZAP }{}xmsg; print qq{lazy .*?: '$t'}; " 'keep me ZIP delete this ZAP also keep this ZIP kill too ZAP keep too' greedy .*: 'keep me keep too' lazy .*?: 'keep me also keep this keep too'
Give a man a fish: <%-{-{-{-<
In reply to Re: How to modify my regex?
by AnomalousMonk
in thread How to modify my regex?
by OldChamp
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |