I need to perform a very simple task in JS, but coming from PHP, it’s unknown territory for me…
So I need to extract the first number from a string. The string can be one of these:
180gr.
140gr. - 200gr.
unlimited food
So, in the above cases I want to extract 180 for the first string, 140 for the second, and an empty string for the third one.
In PHP, the command to do that would be preg_match( '/^d*/', $string, $matches );
.
Can someone help me figure out how to write this in JS?