【发布时间】:2014-11-06 13:39:29
【问题描述】:
我想使用 C# 计算字符串中正则表达式匹配的次数。我使用这个网站来帮助验证我的正则表达式:http://regexpal.com/
我的正则表达式是:
Time(\\tChannel [0-9]* \(mV\))*
这是输入字符串:
Time\tChannel 1 (mV)\tChannel 2 (mV)\tChannel 3 (mV)\tChannel 4 (mV)\tChannel 5 (mV)\tChannel 6 (mV)\tChannel 7 (mV)\tChannel 8 (mV)\tChannel 1_cal (mg/L)\tChannel 2_cal ()\tChannel 3_cal ()\tChannel 4_cal ()\tChannel 5_cal ()\tChannel 6_cal ()\tChannel 7_cal ()\tChannel 8_cal ()\tMotor 1 (mm)\tMotor 2 (mm)
我的期望是,对于我的输入字符串,我的正则表达式应该产生 8 个匹配项。但我似乎找不到计算这个数字的方法。有人可以帮忙吗?
【问题讨论】:
-
这个问题不应该作为重复而关闭。这个问题询问关于计算 pattern 在字符串中出现的次数,而 referenced question 询问关于计算 fixed string 的次数。