Hi could please tell me what is the proper regex expression for parsing font-size css style? I mean that for any of these:
15px
15.23em
234.43rem
12.342pt
I would like to get pairs with the value and unit i.e. (15, px), (15.23, em) etc.
>Solution :
The easiest way is to simply solve it with 2 regex patterns and parse them into a string literal. To get a chain of connected numbers you can use /[0-9]+/ where the + will not only take the first number but all numbers connected to it. to include a decimal dot you need to use \. and can combine them to /[0-9]+\.[0-9]/.
To filter for letters you can use [aA-zZ] that includes both lowerCase and upperCase letters.
const VALUE = '15.6rem';
console.log(`(${VALUE.match(/[0-9]+\.[0-9]+/)}, ${VALUE.match(/[aA-zZ]+/)})`);