javascript - How to find all regex match in a string -


this might simple find on web got problem finding answer.

i string http response text contain substrings want grab 1 one further process. relative url.

for example:

var string = "div classimage hrefstring1.png img idemic00001 he19.56mm wi69.85mm srcstring1.png  separated html         div classimage hrefstring2.png srcstring2.png div separated html many such relative urls"; var re = new regexp("[a-z]{5,10}[0-9].png"); var match = re.exec(string) wscript.echo (match); 

this gives first match. want collection 1 one. using jscript. new javascript.

after answer tried this.

var string = "div classimage hrefstring1.png img idemic00001 he19.56mm wi69.85mm srcstring1.png  separated html         div classimage hrefstring2.png srcstring2.png div separated html many such relative urls"; var re = new regexp("[a-z]{5,10}[0-9].png", "g"); var match = re.exec(string) wscript.echo (match); 

but no luck.

use 'g' global search , match matches:-

var string = "div classimage hrefstring1.png img idemic00001 he19.56mm wi69.85mm srcstring1.png  separated html         div classimage hrefstring2.png srcstring2.png div separated html many such relative urls";    var re = new regexp("[a-z]{5,10}[0-9].png", 'g');    var matches = string.match(re);    for(var = 0; < matches.length; i++){      console.log(matches[i]);  }


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -