I have the following JavaScript Regex
As used in /
\[.*(\.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:[email protected]]
- s[cid:[email protected]]<
- image.jpg
- [cid:[email protected]]
- [cid:[email protected]]
- [cid:[email protected]]
- [[cid:[email protected]]
And again
[cid:[email protected]]]- 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,
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:[email protected]]
- s[cid:[email protected]]<
- image.jpg
- [cid:[email protected]]
- [cid:[email protected]]
- [cid:[email protected]]
- [[cid:[email protected]]
And again
[cid:[email protected]]]- 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,
Share Improve this question asked May 9, 2012 at 12:47 Phill DuffyPhill Duffy 2,8663 gold badges33 silver badges48 bronze badges1 Answer
Reset to default 20You need to modify your regexp to change the greediness (note the .*?
):
\[.*?(\.jpg|\.png|\.gif|\.bmp|\.jpeg).*?\]