Regex to match lines not containing a word

I was trying to create a regex, to be used in a grep statement to match lines that do not contain a word. In the example below I have the words uhu, uhuu, uhuuu, uhuuu one in each line. I used an echo to do that in one command. Results are:

line1 = uh - end
line2 = uhu - end
line3 = uhuu - end
line4 = uhuuu - end
line5 = uhuuuu - end

Never mind the line number and the end word. So, I wanted to grep uhuu's with 2 and 4 repetitions only, that is line 3 and 5. I tried:

echo -e 'line1 = uh - endnline2 = uhu - endnline3 = uhuu - endnline4 = uhuuu - endnline5 = uhuuuu - end' | grep -E 'uh(u{2}|u{4})'
line3 = uhuu - end
line4 = uhuuu - end
line5 = uhuuuu - end

It brings line 3 and 5, but also line 4 because uhuuu has 2 u's, plus a 3rd one. So my question is, using Regex, is it possible to exclude that 4th line taking into account only the 'uhuuu' word?

I know I could accomplish this with a pipe and grep -v at the end of everything but I was wondering if this could be done using RegEx.

I checked this link but couldn find a way to make it work for my case. Thank you https://stackoverflow.com/questions/406230/regular-expression-to-match-line-that-doesnt-contain-a-word#=


分组后使用字边界元字符:

grep -E 'uh(u{2}|u{4})b'
链接地址: http://www.djcxy.com/p/2164.html

上一篇: 用管道连接几个Popen命令

下一篇: 正则表达式匹配不包含单词的行