Jump to content
  • Advertisement
Sign in to follow this  
onceloving

[web] Extracting a Number from a text string

This topic is 4818 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Let's say that q="12r"; Now there is no guarantee how many numbers there will be or how many characters after the numbers. How can I extract just the numbers from that expression?

Share this post


Link to post
Share on other sites
Advertisement
it really depends on the language. a simple regex like /\d*/ will work. how to do it exactly will depend on the language you use.

ruby: "12r".match(/\d*/)
php: preg_match('/\d*/',"12r", $match); // $match[0] contains the number
... the list goes on.

also a lot of languages will convert strings to integers and will just take the first series of digits it comes across (example ruby: "12r".to_i == 12)

Share this post


Link to post
Share on other sites
I was looking more for a built in javascript function that would do it. I can do it with php easily, but I'd rather find a way to do it with javascript only.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!