-1

I need a javascript code to extract number from string like "pushedProductType0".

Saurabh Kumar
  • 15,763
  • 47
  • 125
  • 205

1 Answers1

3
alert( "pushedProductType0".match(/\d/) )
Billy Moon
  • 54,763
  • 23
  • 128
  • 231
  • This will get the 1st number, and only single digits. You should do `.match(/\d+/g)` – gen_Eric Jul 20 '11 at 15:01
  • I agree with `/\d+/` but the global flag is not appropriate as it would return an array. This is just a starter for 10, the question is not specific enough to develop any further – Billy Moon Jul 20 '11 at 15:22
  • Any hint on getting the `last one` ? Here's my question: http://stackoverflow.com/questions/11059054/get-and-replace-the-last-number-on-a-string-with-javascript-or-jquery – Mr_Nizzle Jun 15 '12 at 22:48