Probably extremely obvious but I don't really get along with regex...
I am trying to extract the font name from a sass file containing a @font-face in javascript. The example would be the following:
Given this string:
@font-face {
font-family: 'fancy-icons';
src:
url('#{$icon-font-path}/fancy-icons.ttf?p3owtd') format('truetype'),
url('#{$icon-font-path}/fancy-icons.woff?p3owtd') format('woff'),
url('#{$icon-font-path}/fancy-icons.svg?p3owtd#fancy-icons') format('svg');
font-weight: normal;
font-style: normal;
}
I want to extract the word fancy-icons
, meaning the string within the single quotes and it could be anything.
The closes attempt led me to this code:
const scssContent = fs.readFileSync(path.resolve('fonts.scss'), 'utf-8');
scssContent.match(new RegExp(/font-family: '(.*?)';/g));
but all I am getting is the whole font-family: 'fancy-icons';
.
Thanks in advance.