Last Updated: February 25, 2016
·
202
· prisme

font shorthand regex

I needed to replace shorthand declarations across a whole project and took a while writing the regex, so here it goes for later reference :

(font:) ([a-zA-Z]+) ((?:\d*\.)?\d+em)\/((?:\d*\.)?\d+em) (whatever font-families;)

which you can then replace with :

font-weight: $2;
font-size: $3;
line-height: $4;
font-family: $5

and then, for those without line-height :

(font:) ([a-zA-Z]+) ((?:\d*\.)?\d+em) ("whatever font-families;)

replace :

font-weight: $2;
font-size: $3;
font-family: $4