Hi, so I have this regular expression that is looking for a number.
The text has an hour, and I want to extract the number.
Its in the form: xxx hours (where x is the number).
What I have:
Code:
var pattern = /.*([0-9]{1,3})\W*h/i;
var matches = pattern.exec (text);
I want a number that can have from 1 to 3 digits, the problem is that 'matches' only gets a string with the number with one digit (the last digit), even if text has a number with more digits.
If I change the part within the parentheses for {2}, it works well for 2 digits, etc.
Is there a way to get the most digits, instead of just the least that conform with the pattern?
First the number is not limited to three digits (although I guess I can deal with that later).
If I have more than 1 space after the number, it gives null... but you do have the * there..
Bookmarks