Question: I am having some trouble with this regex:

```
<img(.+)src="_image/([0-9]*)/(.+)/> 

```

Global and case insensitive flags is on.

The problem is that it also grabs Image n (see string below), but I want it only to match the image tags in the string.

```
<p>Image 1:<img width="199" src="_image/12/label" alt=""/> Image 2: <img width="199" src="_image/12/label" alt=""/><img width="199" src="_image/12/label" alt=""/></p>

```

It works if I put a newline before Image n :)

Can anyone point out for me what I am doing wrong?

Thanks in advance 
bob

Answer: 
Use a non-greedy regexp:

<img .*? src="\_image/(\d+)/(.+?)/.*?>
You're using a *greedy* quantifier (+) without much restriction. A greedy quantifier is telling the regex engine: "Grab every character that qualifies and only back off enough to complete the regex." That means that it will get from the first sequence of the characters "image/*nnnnnn*/*something*/".