Match string not containg a certain phrase

丶灬走出姿态 提交于 2019-12-14 03:19:28

问题


I need to find all instances of the word "confidential" in a message except when it is used in the phrase "confidential and proprietary" in which case it is ok and I dont need to pick it up through regex.

Thanks all in advance! -P


回答1:


Using word boundaries \b is also an option here.

\bconfidential\b(?! and proprietary\b)



回答2:


You can use negative lookaround (http://www.regular-expressions.info/lookaround.html)

This regex will match: (confidential) (?!and proprietary) if your engine support lookaround.

demo: http://regexr.com?36itq



来源:https://stackoverflow.com/questions/19145348/match-string-not-containg-a-certain-phrase

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!