c# - Not greedy quantification in regular expression -
i have string m(2,n(3)) . i need retrieve matches (calls) regex: m(2,n(3)) n(3) my variant of regex - (m|n\((.*?)\)) it doesn't work. you can make use of balanced constructs in .net regex. positive look-ahead can match nested expressions this: (?=(\b\w+\b\((?>[^()]+|\((?<n>)|\)(?<-n>))*(?(n)(?!))\))) the values stored in group 1. see demo (go table tab see actual results). var rx = new regex(@"(?=(\b\w+\b\((?>[^()]+|\((?<n>)|\)(?<-n>))*(?(n)(?!))\)))"); var str = "m(2,n(3)), call(param,3)"; var matches = rx.matches(str).oftype<match>().select(p => p.groups[1].value).tolist();