【发布时间】:2011-12-03 12:20:29
【问题描述】:
我有这个 sn-p 来执行正则表达式搜索:
public IEnumerable<MyMatch> GetMyMatches()
{
Match m = myRegex.Match(Text, offset);
if (m != null && m.Success && m.Value != null && m.Value.Length > 0)
{
offset = m.Index+m.Length;
yield return new MyMatch() { Match=m, SomeFurtherInformation=... };
} else
yield break;
}
如您所见,我遍历了文本中的所有出现。
但是如何反转搜索方向?
感谢您的帮助
【问题讨论】:
-
注意:m != null 始终为真,m.Value != null 也始终为真,除非有异常(如偏移量太大)但没有 m :-) 如果有不匹配,值 == ""。
标签: c# regex search ienumerable