The greedy regex property causes the regex engine to repeat a regex token as often as possible. Only if that causes the entire regex to fail, give up the last iteration, and proceed with the remainder of the regex. The greedy regex tokens are `+`, `*`, `?` and the repetition using curly braces.
Example of Greediness
Using a regex to match an HTML tag the regular expression does not need to exclude any invalid use of sharp brackets. An HTML tag will be anything between sharp brackets.
If the test string is the following:
This is a <EM>first</EM> test.
With the <.+>
patterh a expected match would be <EM>
and when continuing after </EM>
. But he regex will match <EM>first</EM>
.
The reason is that the plus is a greedy token.