regexregex-lookaroundsregex-look-ahead

Regex lookahead+lookbehind OR instead of AND


so I have this regex:

(?<![a-zA-Z])(0)(?![a-zA-Z])

it caches "0"s that don't have a letter before AND no letter after

I want to catch "0"s that either don't have a letter before OR don't have a letter after.

Regex101


Solution

  • You could use the OR operator |:

    (?<!\w)0|0(?!\w)

    regex101