有没有一种理论框架EX pression大小限制"或"运营商对Regex.Replace运营商、框架、大小、理论

由网友(wuli小魔女)分享简介:有一个理论框架EX pression大小限制在Regex.Replace或操作符如Regex.Replace(ABC,(A | C | D | E ...继续说500000元素在这里),ZZZ)Is there a theorical expression size limit for "or" operator...

有一个理论框架EX pression大小限制在Regex.Replace或操作符 如Regex.Replace(ABC,(A | C | D | E ...继续说500000元素在这里),ZZZ)

Is there a theorical expression size limit for "or" operator on Regex.Replace such as Regex.Replace("abc","(a|c|d|e...continue say 500000 elements here)","zzz") ?

在.NET的实现任何stackoverflowException?

Any stackoverflowException on .NET's implementation ?

感谢

推荐答案

没有理论上限,但每一个普通的前pression引擎都会有自己的实现的限制。在这种情况下,由于您使用的是.NET的限制是由于.NET运行时可以使用的内存量。

There is no theoretical limit, though each regular expression engine will have its own implementation limits. In this case, since you are using .NET the limit is due to the amount of memory the .NET runtime can use.

一个普通EX pression一百万alernations正常工作对我来说:

A regular expression with one million alernations works fine for me:

string input = "a<142>c";
var options = Enumerable.Range(0, 1000000).Select(x => "<" + x + ">");
string pattern = string.Join("|", options);
string result = Regex.Replace(input, pattern, "zzz");

结果:

azzzc

这是非常缓慢的,但。越来越多的期权数量10万给我的 OutOfMemoryException异常

您可能会受益于寻找另一种方法。

You probably would benefit from looking at another approach.

阅读全文

相关推荐

最新文章