当前位置: 编程技术>其它
asp.net 正则表达式的应用
来源: 互联网 发布时间:2014-10-16
本文导语: 1. 平衡组/递归匹配 (?'group') 将名为group对应的内容,压栈计数; (?'-group') 将名为group的对应的内容, 出栈计数 (?!) 零宽负向先行断言,由于没有后缀表达式,试图匹配总是失败 正则样例: ,{0,1}"5":[[^[]]*(((?'Open'[)[^[]]*)+((?'-Open'])[^[]...
1. 平衡组/递归匹配
(?'group') 将名为group对应的内容,压栈计数;
(?'-group') 将名为group的对应的内容, 出栈计数
(?!) 零宽负向先行断言,由于没有后缀表达式,试图匹配总是失败
正则样例:
,{0,1}"5":[[^[]]*(((?'Open'[)[^[]]*)+((?'-Open'])[^[]]*)+)*(?(Open)(?!))],{0,1}
测试数据:
{"0":["0","0-1","0-2"],"1":["1","1-1","1-2"],"2":["2","2-1","2-2"],"3":["3","3-1","3-2"],"4":["4","4-1","4-2"],"5":["5","5-1","5-2"]}
比对结果:,"1":["1","1-1","1-2"],
评语:这个写的很不错。可以达到取出最近的一个]的效果
2. 零宽断言
(?=exp) 匹配exp前面的位置
(?(?