Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

4
  • These dont work very well. ("hello123").replace( /(^.+\D)(\d+)(\D.+$)/i,'$2') returns "hello124". In fact, none of these work if the number is at the end of the string. Commented Oct 15, 2014 at 18:23
  • 3
    @user1311069: well, that situation was not included in the answer. It would be constructive if you provided your solution to it. Feel free ;) Commented Oct 15, 2014 at 20:10
  • 1
    @user1311069: provided a few extra methods, satisfying you needs too. Commented Oct 16, 2014 at 8:33
  • 5
    These are way too complicated. "Hello 123 there! 45".match(/\d+/).shift(); works for most needs. Test for null before the .shift() if you're not sure if there's a number in the string. Commented Jul 13, 2017 at 17:38