Raúl Sanpedro
Raúl Sanpedro

Reputation: 366

Regex match given word outside of quotes

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.

Upvotes: 3

Views: 765

Answers (2)

Enissay
Enissay

Reputation: 4953

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

Upvotes: 1

vks
vks

Reputation: 67968

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

You can try this.See demo.

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

Upvotes: 5

Related Questions