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.
Stack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
i want after i have been type 123A0001-123A0100 the result is 100. Or if 123A0123-123A0200 the result is 78. how do i do that?please help.
123A0001-123A0100
100
123A0123-123A0200
78
thanks before.
var str = 'A0001-A0100', match = str.match(/\d+/g); if (match) { alert(+match[1] - +match[0]); }
+ (unary plus) will cast the string to a number (does the same as Number(...)).
+
Number(...)
Add a comment
str.match(/\d+/g)
str.match(/\d+(?=-|$)/g)
There is a calculation plug-in for jQuery.
Calculation plugin
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.