0

I am trying to have a regex to capture all strings with this shape:

(not  (xx))

I.e. a parenthesis, a "not", two empty spaces, two caracters between parenthesis and a closing parenthesis

I have tried:

(not  (*))

But I get:

Invalid regular expression. Nothing to repeat

enter image description here

Any idea ?

1
  • 1
    You seem to not yet know what regular expressions are. See here for the docs. (Note you don't need the / / in VSCode.) So for your case for example it would be \(not \(.*?\)\) (however, your screenshot shows only one empty space, not two). Or, if you actually wanted to match exactly two characters in the parentheses, \(not \(..\)\) Commented Sep 30, 2022 at 10:31

1 Answer 1

2

The Nothing to repeat error is due to the * quantifier used to quantify an opening bracket of a capturing group construct.

You need to 1) escape special ( and ) chars, and 2) match any text between the closest ( and ) with a negated character class, here, with [^()]*:

\(not  \([^()]*\)\)

Details:

  • \(not \( - a (not ( string
  • [^()]* - zero or more chars other than ( and )
  • \)\) - a )) string.

If there can be any zero or more whitespace chars between not and (, replace the literal spaces with \s*. If there must be one or more whitespaces, use \s+ instead:

\(not\s*\([^()]*\)\)
\(not\s+\([^()]*\)\)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.