0

Reg Expression for Getting Text with particular function name and with nested parentheses, I had tried but i am not getting the RegEx. For this example

ignore if open or close parentheses between single quotes or double quotes.

eg: strcat("thanks for", param(add(a,b)), ' and ( valuable time ).')

Regex.Matches(script, @"(?x) \( ( (?: [^()]+ | (?<open>\() |
                           (?<-open>\)) )* (?(open)(?!)) ) \)");

Example:-

blelow one is the string and function name is param,

if(a>b, param(add(c,d)), param(2));

Output =>

1) param(add(c,d))

2) param(2)
Thulasiram
  • 8,432
  • 8
  • 46
  • 54

1 Answers1

0

Try this regex:

\b(?!if)\w+\s*\(.+?\)(?!\)\s*,)

Description

Regular expression visualization

Demo

http://regexr.com?37grl

Discussion

You should customize this regex with other reserved keywords that accept parenthesis (switch for instance).

\b(?!if|switch)\w+\s*\(.+?\)(?!\)\s*,)

However, in your case, a C# parser is more appropriate.

Community
  • 1
  • 1
Stephan
  • 41,764
  • 65
  • 238
  • 329