I have a string in JavaScript (e.g., #box2), and I just want the 2 from it.
I tried:
var thestring = $(this).attr('href');
var thenum = thestring.replace(/(^.+)(\w\d+\w)(.+$)/i, '$2');
alert(thenum);
It still returns #box2 in the alert. How can I get it to work?
It needs to accommodate for any length number attached on the end.
Watch video regex - How can I extract a number from a string in JavaScript? online without registration, duration hours minute second in high quality. This video was added by user Code Samples 06 April 2024, don't forget to share it with your friends and acquaintances, it has been viewed on our site 120 once and liked it 2 people.