Regex using javascript to return just numbers

Regular expressions:

var numberPattern = /\d+/g;

'something102asdfkj1948948'.match( numberPattern )

This would return an Array with two elements inside, ‘102’ and ‘1948948’. Operate as you wish. If it doesn’t match any it will return null.

To concatenate them:

'something102asdfkj1948948'.match( numberPattern ).join('')

Assuming you’re not dealing with complex decimals, this should suffice I suppose.

Leave a Comment