3

How to use a posix BRE or a posix ERE regex to match a line that doesn't contain 834 at any place in string?

I want to find grep '!<pattern>' file which will be equal to grep -v '<pattern>' file.

It is theoretical question on regex, that's why I don't want to use -v flag.

I figured out how to list lines, that doesn't contain one character: ^[^8]*$, for my case I also tried ^$|^.$|^..$|^([^8]..|.[^3].|..[^4])*$, but that's not working as expected.

4
  • 2
    ^([^8]*(8([^38]|3[^48])*)*)*$
    – mikeserv
    Commented Nov 16, 2015 at 19:20
  • @mikeserv, not working either :( Commented Nov 16, 2015 at 20:05
  • yeah. think i stuck in one too many asterisks. the (8(...)*)* will match 8 then fall back to the [^8]* when one of the [^3]|3[^4] stuff matches. you have to something very like that - but expanded for all possibilities. regex is math - its why * 0 is a place-holder. negation is perfectly valid regex - you should not try to avoid doing it.
    – mikeserv
    Commented Nov 16, 2015 at 20:07
  • @mikeserv, Anyway, why my pattern is not working? Shouldn't it check each character from beginning of line to be not a part of 834? Commented Nov 17, 2015 at 16:27

1 Answer 1

3

The ^([^8]*(8([^38]|3[^4])+)*)+$ pattern should do the trick, thanks to mikeserv, who pointed it out to me.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .