Communities for your favorite technologies. Explore all Collectives
Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work.
Bring the best of human thought and AI automation together at your work. Learn more
Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
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
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
Add a comment
Something like this should work:
var str = 'minmaxSize12-20'; var range = str.replace(/^.*?Size/i, ''); // returns 12-20
Simply :
"minmaxSize12-20".match(/(\d+)-(\d+)/)
or even
/(\d+)-(\d+)/.exec("minmaxSize12-20");
Required, but never shown
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.
Explore related questions
See similar questions with these tags.