-2

I am currently using the following character class: [^\)\(] in my regex

I want to add the word 'hello' to this class so it is also not matched in my string. I have tried

[^\)\((hello)]

but it does not work.

What can I do?

  • 2
    Duplicate of [Regular expression to match a line that doesn't contain a word](https://stackoverflow.com/questions/406230/regular-expression-to-match-a-line-that-doesnt-contain-a-word), [match everything but specific pattern](https://stackoverflow.com/q/1687620/8967612). – 41686d6564 stands w. Palestine Aug 13 '20 at 08:54
  • You could very well use `[^t()]` instead. – Jan Aug 13 '20 at 08:57

1 Answers1

1

One typical way you would enforce that hello does not appear would be to use a negative lookahead, e.g.

^(?!.*hello)[^t()]+$

If you only wanted to exclude hello when it appears as a bona fide word, then surround it with word boundaries in the lookahead:

^(?!.*\bhello\b)[^t()]+$
Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360