c# - Use Regex to remove outer parentheses from nested expression, but leave inner parentheses? -
i'm working on figuring out regular expression take value such as:
transformer winding connections (wye (star) or delta) and match:
wye (star) or delta what have far is:
string longname = "transformer winding connections (wye (star) or delta)"; // match until first parentheses regex nameregex = new regex(@"([^(]*)"); match namematch = nameregex.match(longname); // match first parentheses on regex valueregex = new regex(@"\(.+\)"); match valuematch = valueregex.match(longname); valuematch returning:
(wye (star) or delta) is there clever way remove first set of parentheses in c#?
if want deal 1 level fine.
@"\((?:\([^()]*\)|[^()])*\)" or
if don't want match outer paranthesis.
@"(?<=\()(?:\([^()]*\)|[^()])*(?=\))"
Comments
Post a Comment