javascript - Finding the font in a css file with regex -
i attempting string regex find fonts used in css file. far have follows.
var regexp = /font-family:(\w+);/; var matches = regexp.exec("font-family:arial; font-family:berch;"); //matches[1] contains value between parentheses console.log(matches);
this matches 'arial'. how can make carry on searching find 'berch'?
add g
modifier regex.
var regexp = /font-family:(\w+);/g;
g
(global) modifier says not stop after first match , match pattern can.
also don't use exec
. use string.match
.
"font-family:arial; font-family:berch;".match(/font-family:(\w+);/g);
Comments
Post a Comment