gpt4 book ai didi

.net - 支持惰性求值的 .Net 正则表达式库

转载 作者:行者123 更新时间:2023-12-02 08:57:39 25 4
gpt4 key购买 nike

我正在寻找 .Net 中支持惰性求值的正则表达式库。

注意:我专门寻找惰性评估(即,库不是立即返回文档中的所有匹配项,而是仅消耗尽可能多的文档来确定每个请求的下一个匹配项),不支持惰性量词 - 如果它也支持惰性量词,我不会反对!

具体细节:我希望能够针对可能有数十万个正则表达式匹配的非常大的文档运行正则表达式,并使用 IEnumerable<> 迭代结果语义,而无需承担查找所有匹配项的前期成本。

理想情况下是 C# 中的 FOSS,但唯一的要求是 .Net 3.5 应用程序的可用性。

最佳答案

比赛类'NextMatch method应该可以满足您的需求:

Returns a new Match with the results for the next match, starting at the position at which the last match ended (at the character after the last matched character).

在 Reflector 中快速查看可以确认此行为:

public Match NextMatch()
{
if (this._regex == null)
{
return this;
}
return this._regex.Run(false, base._length, base._text, this._textbeg,
this._textend - this._textbeg, this._textpos);
}

查看链接的 MSDN 引用以获取其用法示例。简而言之,流程类似于:

Match m = rx.Match(input);
while (m.Success)
{
// do work
m = m.NextMatch();
}

关于.net - 支持惰性求值的 .Net 正则表达式库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3702608/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com