[英]What match is occured in Regex
让我们想象一下我有一些正则表达式模式:
(a)|(b)|(c)
如何识别已触发的匹配? 有某种匹配指数吗?
我可以检查所有组为null或将全局值字段与组值字段或单独的模式比较为多个并通过“ if ”行检查它们,但它有点蹩脚并且给出了额外的复杂性。 正则表达式没有一些有限的状态值吗?
当然你可以这样做:
match.Groups[1].Success // true or false
match.Groups[2].Success // true or false
match.Groups[3].Success // true or false
您还可以为群组命名,以便更轻松地遵循:
(?<foo>a)|(?<bar>b)|(?<baz>c)
match.Groups["foo"].Success // true or false
match.Groups["bar"].Success // true or false
match.Groups["baz"].Success // true or false
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.