How to split and select which is number using regex. User can enter string like:
dozen1 <= unlikely but assume user will type that too
I still find out with the incomplete one:
But missing space and forward slash. Can anyone help me?
The lookarounds are completely unnecessary here!
var text = "1dozen 3 dozen dozen1 30/kg"; var regex = /(\d+)/g; alert(text.match(regex));
You get a match object with all of your numbers.
The script above correctly alerts
var str = '1dozen 3 dozen dozen1 30/kg'; str.match(/\d+/g); // ["1", "3", "1", "30"]