Regex match given word outside of quotes

拜拜、爱过 提交于 2020-11-29 08:36:25

问题


I need to be able to match the word "internet" outside of quotations. e;g

Internet "InternetFormula works and it's internetformula"
Internet "The internet works"

But I have no idea how to do so as Regular Expressions is complicated, and I can't find anything like it.


回答1:


\bInternet\b(?=(?:[^"]*"[^"]*")*[^"]*$)

You can try this.See demo.

https://www.regex101.com/r/fG5pZ8/22




回答2:


According to The Greatest Regex Trick Ever, you could use simply the following:

"[^"]*"|\b(Internet)\b

DEMO

All credits goes to Nathan Tuggy for the link



来源:https://stackoverflow.com/questions/27751855/regex-match-given-word-outside-of-quotes

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