问题
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