-1

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

Saurabh Kumar
  • 16,353
  • 49
  • 133
  • 212

1 Answers1

3
alert( "pushedProductType0".match(/\d/) )
Billy Moon
  • 57,113
  • 24
  • 136
  • 237
  • 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