Standalone numbers Regex?

Using lookaround, you can restrict your capturing to only digits which are not surrounded by other digits or decimal points:

(?<![0-9.])(\d+)(?![0-9.])

Alternatively, if you want to only match stand-alone numbers (e.g. if you don’t want to match the 123 in abc123def):

(?<!\S)\d+(?!\S)

Leave a Comment