*
yo**@nobhillsof t.com wrote, On 7-5-2007 21:00:
Hi,
I am trying to write a regexp to find all the code on the header of
entities in SQL Server (views, SPs, etc...) I got something like this:
(.|\n)*((create view)|(create proc)|(create function)|(crea te
trigger))
does that means sense? I want all the code that's before the code
header. now, the problem is, when i give that pattern with some string
buffer to the 'replace' method (I replace it with String.Empty...
meaning i want to remove the header) the whole enviroment just
freezes... the RegExp.Replace method never returns...
anybody has any idea why? or some different regexp that does the same
that may not hit that bug? (i assume its a bug) i am using .net 2.0
thanks
Jonathan
If your input buffer is large enough, (.|\n)* will capture the complete
input first, and then the regex engine will start backtracking. This
takes an enormous amount of both memory and processing power.
You could try the following:
..*?
And add the following RegexOption to your call: RegexOption.Sin gleLine
SingleLine tells the parser to let . match all characters including the
newline. The extra ? at the end tells the parser to evaluate what's
behind the ? on every character and prevents the engine from having to
backtrack too much.
If you're very sure all the code before the header will always start at
the beginning of the input buffer (makes sense to me), fixing your regex
to the start of the string should also improve performance quite a bit:
^.*?(create ((view)|(proc)| (function)|(tri gger)))
Jesse