1

I have a String like the following

 minmaxSize2-8
 minmaxSize12-20

How to get the range from the above strings.I need to get 2-8 and 12-20. Please suggest the regular expressions in javascript

3 Answers 3

5

You can do it like this:

var myString = "minmaxSize12-20";
var myRegexp = /(\d+)-(\d+)/g; // Numbers dash Numbers
var match = myRegexp.exec(myString);
alert(match[1]);  // 12
alert(match[2]);  // 20
Sign up to request clarification or add additional context in comments.

Comments

0

Something like this should work:

var str = 'minmaxSize12-20';
var range = str.replace(/^.*?Size/i, ''); // returns 12-20

Comments

0

Simply :

"minmaxSize12-20".match(/(\d+)-(\d+)/)

or even

/(\d+)-(\d+)/.exec("minmaxSize12-20");

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.