prasad prasad - 1 year ago 92
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

Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download