By default, regular expression matching is greedy, which means they try to match as many matches as possible in a given string.
Lets see an example considering HTML snippet -
<p>Hello</p><span>Awesome</span><p>World</p>. Our task is to extract first
p tag. i.e pattern matching should return
Immediate solution is to write regex -
/<p>.*<\/p>/. But it would match the whole string.
The reason it matches whole string...
- Tags: regex|