Reputation: 16632
With * and + greedies behaves different in the below regexp patterns, why?
This is my text:
hello abcdef ghijklmc happiness<span>Lorem impsum</span> lorem
<p>Lorem impsum</p>Lorem impsum Today is Feb 23rd, 2003
This is regexp:
<[/]?[a-z].*?>
Result:
With this pattern:
<[/]?[a-z].+?>
Result:
Upvotes: 0
Views: 42
Reputation: 943746
Because *
is 0 or more and +
is 1 or more.
When the tag name only has one character in it:
[a-z]
matches the p
.
matches the >
+
the >
has to be matched by the .
to it keeps matching until the next >
(at the end of the next tag)*
, the >
doesn't have to be matched by the .
(since you can have 0 matches) so the >
matches that character instead.>
matches the next >
Upvotes: 5