in reply to Re: searching for a substring in a string
in thread searching for a substring in a string
Greedy quantifiers gobble up every character they can, then back off until a match is made. Lazy quantifiers find as little as possible, then expands what it matches until it can match the rest of the regex. The first search matches the entire string, while the second search matches, "Cats and dogs".$string = "Cats and dogs shouldn't eat hot dogs"; $string =~ m/.*dogs/; # Greedy Quantifier $string =~ m/.*?dogs/; # Lazy Quantifier
If you're getting into Regex, I'd recommend 'Mastering Regular Expressions'. It will provide some invaluable insights into these sorts of things.
|
|---|