prasad prasad - 5 months ago 26
jQuery Question

How to find only numeric values without mix of alphabet values using regex?

I have one equation:

I need separate the numeric values only without mix of alphabetic characters.
I used the regex
to get the all numeric values, but for the equation above, the results should be


You can use an optional hyphen and word boundaries to match only numbers from given expressions:

var str = '+8x2+10y2-99+5=99';

var matches = str.match(/-?\b\d+\b/g);

document.writeln('<pre>' + matches.join(',') + '</pre>');



RegEx Demo