I have some process, that is run over some files that contains a lot of strange data. The process needs to find some string and replace it with something else. Here is the function:
private static string ReplaceRegex(string inputText, string regex, string replacement)
{
return (replacement != null)?new Regex(regex, RegexOptions.IgnoreCase).Replace(inputText, replacement).Trim(): string.Empty;
}
It works properly in most cases, but once I passed to this function an inputText with 3491 chars length, and this string as a regex:
"\[HYPERLINK\]\s*(?:\<[\s\S]*?\>)*\s*([\s\S]*?)\s*(?:\<[\s\S]*?\>)*\s*\[\/HYPERLINK]\s*(?:\<NO1\>)?\s*(?:\<WC1?\>)?\s*\[URL\]\s*(?:\<NO1?\>)?\s*(?:\<WC1?\>)?\s*([\s\S]*?)\s*(?:\<NO1?\>)?\s*(?:\<WC1?\>)?\s*\[\/URL\](?:\<NO1?\>)?(?:\<WC1?\>)?"
The process stucks.
I was waiting that system would throw OutOfMemory exception, but it doesn't, it just stucks. I was waiting for it to response for hours, but it didn't respond.
Any ideas how I can solve this?
EDIT: Thank guys.
Just to be honest, I inherited this code with the project and now trying to figure out what's going on. And I do not know why somebody have done it this way.