Does that RegExp makes sense to you, people?

  • Thread starter Thread starter yoni
  • Start date Start date
Y

yoni

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)|(create
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
 
have a look at regexlib.com, you can test and write your expression there.

--
Regards,
Alvin Bruney
------------------------------------------------------
Shameless author plug
Excel Services for .NET is coming...
OWC Black book on Amazon and
www.lulu.com/owc
Professional VSTO 2005 - Wrox/Wiley
 
Thanks Alvin,
I'll have a look. but whatever the expresion is, why would .net freeze
on me?
 
and oh... it freezes there just the same :) all it is is a web page
that calls the same methods i call... so not much value in it for me
right now. my question still stands....

thanks
Joanthan
 
Is this the exact expression, I don't have a freeze on my machine. Maybe
post some complete code that reproduces the error?

--
Regards,
Alvin Bruney
------------------------------------------------------
Shameless author plug
Excel Services for .NET is coming...
OWC Black book on Amazon and
www.lulu.com/owc
Professional VSTO 2005 - Wrox/Wiley
 
* (e-mail address removed) 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)|(create
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.SingleLine

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)|(trigger)))

Jesse
 
Back
Top