I need a regular expression that matches a string when the user enters it. This is a little hard to explain, so let me show you what I mean:
It should match this line:
"XXXX units" , where XXXX is any number.
But it should also match any substring from the beginning of this line, therefore:
"123" "123 u" "123 uni"
must also match.
But of course this should not match:
"123 xx"
It seems so simple, but I canβt understand it. This is the closest I have:
^\d+ ?u?n?i?t?s?
... but this, unfortunately, also matches strings like "123us".
Can anyone help? This is javascript, so I can be limited a bit by the lack of appearance functions ...
javascript regex
Zissou
source share