I always forget how to create simple regular expressions despite doing projects with more complex regexes...
I have the string:
var s = "qwehref=\"1232.css\"qwasd asd asdqq eehref=\"asd.css\""
I want to capture the text inside the href tags: 1232.css and asd.css.
I've tried with this regex:
var re = /href="(.+\.css)"/g
but this is what I get (re.exec(s)):
'1232.css"qwasd asd asdqq eehref="asd.css'
try
/href="([^"]+\.css)"/g
You don't want to match the closing quote as part of your file name. Or just use a non greedy match I guess...
/href="(.+?\.css)"/g
Greediness problem try
var re = /href="(.+?\.css)"/g
See it here on Regexr
The ? after a quantifier changes the matching behaviour of that quantifier to match as less as possible