Find all strings except one string using regex
This question already has an answer here:
^(?!ABC$).*
匹配除ABC
外的所有字符串。
Judging by you examples, I think you mean "all strings except those containing the word ABC".
Try this:
^(?!.*bABCb)
Invert the Match with GNU Grep
You can simply invert the match using word boundaries and the specific string you want to reject. For example:
$ egrep --invert-match 'bABCb' /tmp/corpus
"A" --> Match
"F" --> Match
"AABC" --> Match
"ABCC" --> Match
"CBA" --> Match
This works perfectly on your provided corpus. Your mileage may vary for other (or more complicated) use cases.
链接地址: http://www.djcxy.com/p/13380.html上一篇: 如何否定正则表达式