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

Popular posts from this blog

windows - Single EXE to Install Python Standalone Executable for Easy Distribution -

c# - Access objects in UserControl from MainWindow in WPF -

javascript - How to name a jQuery function to make a browser's back button work? -