Friday, May 10, 2024
 Popular · Latest · Hot · Upcoming
157
rated 0 times [  162] [ 5]  / answers: 1 / hits: 15809  / 12 Years ago, wed, may 9, 2012, 12:00:00

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





  1. [cid:[email protected]]

  2. s[cid:[email protected]]<

  3. image.jpg

  4. [cid:[email protected]]

  5. [cid:[email protected]]

  6. [cid:[email protected]]

  7. [[cid:[email protected]]
    And again
    [cid:[email protected]]]

  8. 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,


More From » regex

 Answers
8

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



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

[#85699] Monday, May 7, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
mckenna

Total Points: 445
Total Questions: 109
Total Answers: 109

Location: Virgin Islands (U.S.)
Member since Sun, May 16, 2021
3 Years ago
;