RegexOptions.Singleline is causing a timeout?

  • Thread starter Thread starter David P. Donahue
  • Start date Start date
D

David P. Donahue

I'm trying to use the following code to read in a file on my web server
and display part of its contents (sorry for wrapping):

StreamReader streamReaderFile = new StreamReader("/path/to/file.html");
string stringFile = streamReaderFile.ReadToEnd();
stringFile = System.Text.RegularExpressions.Regex.Replace(stringFile,
@".*<!-+\s*-+\s*START\s*HERE\s*-+\s*-->",
"<br>", RegexOptions.Singleline);
....

But the web server seems to be timing out on the third line, where the
Regex is executed. It doesn't time out if I don't use the Singleline
option, but then of course it doesn't do what I need it to do. It's
supposed to be just getting rid of everything in the HTML file up to and
including a comment I placed there:
"<!-- ------------ START HERE ------------ -->"

Any ideas what I'm doing wrong?


Regards,
David P. Donahue
(e-mail address removed)
http://www.cyber0ne.com
 
David P. Donahue wrote:

Any ideas what I'm doing wrong?

I tried your code to be sure and I think you are not really doing
anything wrong. It works fine for me in a sample program. What I would
do now is try to decouple things and get behind the real reason for the
failure:

- Create a simple sample application that has nothing to do with the
web server and put the code in there.

- Extract the exact data that the web server sees from the method
(e.g. by writing the streamReaderFile contents to another file) and use
that data with your test program.

This way you'll be able to find out reliably if the problem lies with
the code, the data, or with a specific detail about the web server itself.



Oliver Sturm
 
Back
Top