Reputation: 1061
I'm using the \((?!\s)([^()]+)(?<!\s)\)
regular expression to match (string)
but not ( string )
nor ()
when searching in Sublime Text.
As VS Code doesn't support backreferences in regular expressions, I was wondering how can modify the original regex to get the same result in this editor.
Any ideas?
Upvotes: 7
Views: 8121
Reputation: 626896
You may use
\(([^()\s](?:[^()]*[^()\s])?)\)
See the regex demo
Details
\(
- a (
char([^()\s](?:[^()]*[^()\s])?)
- Group 1:
[^()\s]
- a char other than (
, )
and a whitespace(?:[^()]*[^()\s])?
- an optional sequence (so as to also match strings like (a)
, with 1 char inside parentheses) of
[^()]*
- 0+ chars other than (
and )
[^()\s]
- a char other than (
, )
and a whitespace\)
- a )
char.Upvotes: 11