Search code examples
regexunixgrepregex-negation

Unix grep regex containing 'x' but not containing 'y'


I need a single-pass regex for unix grep that contains, say alpha, but does not contain beta.

grep 'alpha' <> | grep -v 'beta'

Solution

  • ^((?!beta).)*alpha((?!beta).)*$ would do the trick I think.