i match following tag multiple times.
at moment have this: <img[\w\w]+\/?>
, instead of pick 3 times, find image whole things because match start '', there anyway can match them individually 3 times?
<img src="wp-content/uploads/2015/03/jetty-road-baby.jpeg" alt="jetty" width="100" height="100" />asdasd test <img src="wp-content/uploads/2015/03/jetty-road-baby.jpeg" alt="jetty" width="100" height="100" /> test <img src="wp-content/uploads/2015/03/jetty-road-baby.jpeg" alt="jetty" width="100" height="100" />
cheers bill
you can use possessive quantifiers fix it
/<img[\w\w]+?\/?>/g
the ?
after +
makes +
non-greedy quantifier, ie >
found stops search else continue search till last >
found
- https://developer.mozilla.org/en/docs/web/javascript/guide/regular_expressions#special-questionmark
- lazy-mode
you can try /<img[^>]*\/?>/g
- try find char sequances starting <img
followed number of characters other >
followed /
(optional) , >
.
caution: regular expression based processing of html can buggy in above case attribute of image can have >
in break our regex
Comments
Post a Comment