0

I'm playing with regex and i try used this pattern /\(\((.+?)\)\w+/ to match string that i want.

This is my string

(string,love) (string,string string string(string,string string,string),string) (string string string(string,string string)) (string,string) ((string,string string)string,string)

i expect

(string,string string)string

What i got is

((string,string string)string

I need to match just one '(' symbol, not two '(('.

How to achieve that? Thank you

dany
  • 177
  • 2
  • 13
  • You need `/\(\(([^()]+)\)\w+/`, you need to use `[^()]+` to *match a substring inside parentheses excluding any inner parentheses*. – Wiktor Stribiżew Jul 12 '18 at 16:45
  • I think what you're actually looking for is a [lookbehind](https://www.regular-expressions.info/lookaround.html) to match but not capture the first parenthesis. Albeit just making the appropriate capture group or stripping the remnant opening `(` would be simpler. – mario Jul 12 '18 at 16:47

0 Answers0