Regex lookahead+lookbehind OR instead of AND

103 Views Asked by At

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

1

There are 1 best solutions below

0
VvdL On BEST ANSWER

You could use the OR operator |:

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

regex101