Regex multiple matches on same line

javascript, regex

Solution

You need to modify your regexp to change the greediness (note the `.*?`):

\[.*?(\.jpg|\.png|\.gif|\.bmp|\.jpeg).*?\]

Problem

I have the following JavaScript Regex As used in http://regexpal.com/ `\[.*(\.jpg|\.png|\.gif|\.bmp|\.jpeg).*\]` As use in jQuery code - `post.html().match(/\[.*(\.jpg|\.png|\.gif|\.bmp|\.jpeg).*\]/g);` This is the sample data I am working with - [cid:image001.jpg@01CD2DC8.704399C0] - s[cid:image001.png@01CD2DC8.704399C0]< - image.jpg - [cid:image002.jpg@01CD2DC8.704399C0] - [cid:image002.exe@01CD2DC8.704399C0] - [cid:image002.gif@01CD2DC8.704399C0] - [[cid:image001.jpg@01CD2DE6.9802A2D0] And again [cid:image002.png@01CD2DE6.9802A2D0]] - test.gif My issue is that on line 7, I would like the two strings enclosed in the [] to be separate, at the moment it is treating the whole line as a match,

Original source