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”) ?
Any stackoverflowException on .NET’s implementation ?
Thanks
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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.
A regular expression with one million alernations works fine for me:
Result:
It’s very slow though. Increasing the number of options to 10 million gives me an
OutOfMemoryException.You probably would benefit from looking at another approach.