.net – 正则表达式跟踪`)`[复制]
发布时间:2020-12-14 06:01:06 所属栏目:百科 来源:网络整理
导读:参见英文答案 Using RegEx to balance match parenthesis????????????????????????????????????4个 ???????????? Matching Nested Structures With Regular Expressions in Python????????????????????????????????????6个 让我说我的输入是fn(a(b,c),d)fn(a
参见英文答案 >
Using RegEx to balance match parenthesis????????????????????????????????????4个
>???????????? Matching Nested Structures With Regular Expressions in Python????????????????????????????????????6个 让我说我的输入是fn(a(b,c),d)fn(a,d)fn(a(b),d)我想要一个(b,d我怎么写一个模式来得到()里面的一切?第二个fn()很容易第一个和第三个我不知道如何匹配 解决方法
你需要
balancing group definitions:
result = Regex.Match(subject,@"(?<=() # Make sure there's a ( before the start of the match (?> # now match... [^()]+ # any characters except parens | # or ( (?<DEPTH>) # a (,increasing the depth counter | # or ) (?<-DEPTH>) # a ),decreasing the depth counter )* # any number of times (?(DEPTH)(?!)) # until the depth counter is zero again (?=)) # Make sure there's a ) after the end of the match",RegexOptions.IgnorePatternWhitespace).Value; (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |