im trying to parse a javascript file to return font-face urls.
the file look like this
@font-face {
font-family: 'AlfaSlab';
iesrc: url('/lib/assets/themes/ek/skins/default/alfaslabone-regular-webfont.eot');
url('/lib/assets/themes/ek/skins/default/alfaslabone-regular-webfont.woff')
i want to grab all font links with file extensions (eot,woff,svg,otf)
i came up with this regex /(\/lib\/.*?\/.*?\.(eot|woff|ttf|svg))/ but its returning also the file extensions (because the () in the file extensions)
in ruby im doing this files.map {|file| File.read(file).scan(regex)} #=> ['/lib/assets/themes/ek/skins/default/alfaslabone-regular-webfont.eot','eot','/lib/assets/themes/ek/skins/default/alfaslabone-regular-webfont.woff','woff']
how can i fix the regex to only return the file path instead of the file path + file extension in 2 array elements, thanks 🙂
EDIT:
i want to return the whole path with the file extension, ['/lib/assets/themes/ek/skins/default/alfaslabone-regular-webfont.eot','/lib/assets/themes/ek/skins/default/alfaslabone-regular-webfont.woff'] should be the match.. thanks for your time
You can rewrite your regex:
[\w\-\/]defines a set of characters:\wword character, i.e. letter (a-z,A-Z), number (0-9) and underscore (_)\-hyphen (-)\/slash (/)+means one or more of these characters\.is the dot before the file extension(eot|woff|ttf|svg)is the file extension?:tells the regex engine to not generate a backreference for this capturing group