c# - Regex, match string ending with ) and ignore any () inbetween -
this question has answer here:
- using regex balance match parenthesis 4 answers
i want select part of string, problem last character want select can have multiple occurrences.
i want select 'aggregate('
, end @ matching ')'
, ()
in between can ignored.
examples:
string: substr(aggregate(subquery, sum, [model].remark * [object].shortname + 10), 0, 1)
should return: aggregate(subquery, sum, [model].remark * [object].shortname + 10)string: substr(aggregate(subquery, sum, [model].remark * ([object].shortname + 10)), 0, 1)
should return: aggregate(subquery, sum, [model].remark * ([object].shortname + 10))string: substr(aggregate(subquery, sum, ([model].remark) * ([object].shortname + 10) ), 0, 1)
should return: aggregate(subquery, sum, ([model].remark) * ([object].shortname + 10) )
is there way solve regular expression? i'm using c#.
this little ugly, use like
aggregate\(([^()]+|\(.*?\))*\)
it passes tests, can match 1 level of nested parentheses.
Comments
Post a Comment