3

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.

Raúl Sanpedro
  • 266
  • 4
  • 15
  • 1
    Similar enough to [Can regex match all the words outside quotation marks?](http://stackoverflow.com/questions/26003778/can-regex-match-all-the-words-outside-quotation-marks) it's probably a dupe, assuming your regex engine is Perl-compatible. – Nathan Tuggy Jan 03 '15 at 05:15

2 Answers2

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

You can try this.See demo.

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

vks
  • 67,027
  • 10
  • 91
  • 124
  • Note that this technique works as long as you don't have an unmatched quote after a found match. Depending on the multi-line setting this will either select all cases of `Internet` regardless of quotes, or only cases of `Internet` within quotes. Is there a way to have it work without this limitation? – Ben Oct 19 '20 at 13:34
  • @Ben the answer is based on assumption having balanced quotes.... :) – vks Oct 19 '20 at 13:48
  • No worries. I just wanted to point out this limitation since [my similar question](https://stackoverflow.com/questions/64421889/vba-regex-to-find-word-not-in-quotes?noredirect=1#comment113916433_64421889) was redirected to this one. I had challenges until I noticed the limitation. – Ben Oct 19 '20 at 14:41
1

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

Enissay
  • 4,969
  • 3
  • 29
  • 56
  • Note that this technique works if you have code to process the returned matches and can focus only on Group 1. It doesn't work (from my testing) if you want to use Substitution (without additional processing) to replace the found word with another word. – Ben Oct 19 '20 at 13:30