How can I write a regex which matches non greedy? [duplicate]

I need help about regular expression matching with non-greedy option.

The match pattern is:

<img\s.*>

The text to match is:

<html>
<img src="https://stackoverflow.com/questions/11898998/test">
abc
<img
  src="a" src="a" a=b>
</html>

I test on http://regexpal.com

This expression matches all text from <img to last >. I need it to match with the first encountered > after the initial <img, so here I’d need to get two matches instead of the one that I get.

I tried all combinations of non-greedy ?, with no success.

3 Answers
3

Leave a Comment