Skip to main content
The 2024 Developer Survey results are live! See the results

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.

3
  • Surprised after reading the high voted accepted answer, I scrolled down to write about its narrow scope and to actually address the spirit of the question. I should have guessed that someone would have done it years ago already. This is very well explained and is the true correct answer.
    – Amit Naidu
    Commented May 19, 2019 at 6:39
  • This is a little hacky and doesn't generalise well. The problem with this approach is that the pattern [^0-9]*([0-9]+)[^0-9]* needs to be designed in such a way that it never crosses the boundary of another match. That works OK for this example, but for complex search queries that don't work on a character-by-character basis, it isn't very practical to have to surround the actual desired match group (whatever) which its forward-lookup and reverse-lookup negation.
    – Myridium
    Commented Jan 14, 2022 at 4:16
  • 1
    It also needs to capture everything that is not part of the capture groups.
    – Myridium
    Commented Jan 14, 2022 at 4:29