473,394 Members | 1,671 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

vs.net 2005 regular expression infinite loop...

I have a aspx file (snippet shown below):

=======
<td class="light-m1" id="rwCompleteButton" runat="server"><br/>
<asp:ImageButton CssClass="clear-m1" runat="server"
CommandName="Complete" ID="btnComplete" />

<asp:ImageButton CssClass="clear-m1" runat="server"
CommandName="Delete" ID="btnDelete" />
</td>
=======

and the following .cs file to execute (snippet below)

========
strReg = @"(<\w+:(.|[\r\n])*?id=""btnComplete"")([^>]+>)";
reg = new Regex(strReg);
if (!reg.IsMatch(uiStr))
{
blah...blah...
}
========

The if statement above is going to infinite loop. However, when I try the
expression on Expresso (a third party tool written in vs.net 2003) it matches
just fine.

Any ideas?
--
-jojobar
Mar 6 '06 #1
11 1725
sorry forgot to mention that I am first reading the aspx file in the uiStr
before executing this code.

Thanks
--
-jojobar
"jojobar" wrote:
I have a aspx file (snippet shown below):

=======
<td class="light-m1" id="rwCompleteButton" runat="server"><br/>
<asp:ImageButton CssClass="clear-m1" runat="server"
CommandName="Complete" ID="btnComplete" />

<asp:ImageButton CssClass="clear-m1" runat="server"
CommandName="Delete" ID="btnDelete" />
</td>
=======

and the following .cs file to execute (snippet below)

========
strReg = @"(<\w+:(.|[\r\n])*?id=""btnComplete"")([^>]+>)";
reg = new Regex(strReg);
if (!reg.IsMatch(uiStr))
{
blah...blah...
}
========

The if statement above is going to infinite loop. However, when I try the
expression on Expresso (a third party tool written in vs.net 2003) it matches
just fine.

Any ideas?
--
-jojobar

Mar 6 '06 #2
Hi Jojobar,

Welcome to ASP.NET newsgroup.

As for the regex problem you mentioned, I think you can first test the
regex through the .net regulator tool which is a pure .net developed regex
testing tool:

http://sourceforge.net/project/showf...roup_id=105210

also, from the code you provided, you used the following regex expression:

strReg = @"(<\w+:(.|[\r\n])*?id=""btnComplete"")([^>]+>)";

based on my test, the original regex should be
(<\w+:(.|[\r\n])*?id="btnComplete")([^>]+>) and you use "" to escape " ,
yes?
If so, this will not work in .net because "" is not the correct escape for
" in C#, you may consider use

strReg = "(<\\w+:(.|[\\r\\n])*?id=\"btnComplete\")([^>]+>)" , anyway
manually replace each particular char with the escaped one in C# format.

Hope this helps.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Mar 7 '06 #3
Hello Steven,

Thank you for your time. I tested it with a tool called expresso which is
(in my opinion) a better regex evaluator tool.

Also the two "" you mentioned is there because I used a string literal to
escape the quotes. For exanmple

str = @"This is ""a''" test"
and
str = "This is \"a\" test"

are equivalent.

BTW I changed my expression to the second form and it still goes inside
infinite loop!
Thanks
--
-jojobar
"Steven Cheng[MSFT]" wrote:
Hi Jojobar,

Welcome to ASP.NET newsgroup.

As for the regex problem you mentioned, I think you can first test the
regex through the .net regulator tool which is a pure .net developed regex
testing tool:

http://sourceforge.net/project/showf...roup_id=105210

also, from the code you provided, you used the following regex expression:

strReg = @"(<\w+:(.|[\r\n])*?id=""btnComplete"")([^>]+>)";

based on my test, the original regex should be
(<\w+:(.|[\r\n])*?id="btnComplete")([^>]+>) and you use "" to escape " ,
yes?
If so, this will not work in .net because "" is not the correct escape for
" in C#, you may consider use

strReg = "(<\\w+:(.|[\\r\\n])*?id=\"btnComplete\")([^>]+>)" , anyway
manually replace each particular char with the escaped one in C# format.

Hope this helps.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Mar 7 '06 #4
Thanks for your response Jojobar,

I think the problem could be related to the RegexOptions we set to the
Match function or regex's construtor. I've just performed the test in a
..net 2.0 winform application and it can work. The test code is like below:

============================

string doc = .................;

string regex = "(<\\w+:(.|[\\r\\n])*?id=\"btnComplete\")([^>]+>)";

MatchCollection matchs = Regex.Matches(doc, regex, RegexOptions.Compiled |
RegexOptions.IgnoreCase);

MessageBox.Show(matchs.Count.ToString());
======================

You can also have a test on your side to see whether this is the case.

Hope this helps.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Mar 8 '06 #5
Yes it works now. Thanks for your help. I think the options
made it to work. Maybe the infinite loop thing need to be reported to the ms
development anyways.

Thanks
--
-jojobar
"Steven Cheng[MSFT]" wrote:
Thanks for your response Jojobar,

I think the problem could be related to the RegexOptions we set to the
Match function or regex's construtor. I've just performed the test in a
.net 2.0 winform application and it can work. The test code is like below:

============================

string doc = .................;

string regex = "(<\\w+:(.|[\\r\\n])*?id=\"btnComplete\")([^>]+>)";

MatchCollection matchs = Regex.Matches(doc, regex, RegexOptions.Compiled |
RegexOptions.IgnoreCase);

MessageBox.Show(matchs.Count.ToString());
======================

You can also have a test on your side to see whether this is the case.

Hope this helps.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Mar 8 '06 #6
Hello,

I just tested it again, I find that with the example you have given, it is
also going into infinite loop.

Here is the code:

string uiStr = Utils.OCFile.ReadTextFile("taskcontrol.ascx");

string regex = "(<\\w+:(.|[\\r\\n])*?id=\"btnRecurrenceAdd\")([^>]+>)";

MatchCollection matchs = Regex.Matches(uiStr, regex, RegexOptions.Compiled
| RegexOptions.IgnoreCase);

if (matchs.Count == 0)
{
MessageBox.Show("Failed.");
}
else
{
MessageBox.Show("Success");
}

The statement matchs.Count is going into infinite loop

Note that the file taskcontrols.ascx is little big to put here, so it is in
http://www.my-email-signature.com/Test/test.zip and you can download it from
there.
--
-jojobar
"jojobar" wrote:
Hello Steven,

Thank you for your time. I tested it with a tool called expresso which is
(in my opinion) a better regex evaluator tool.

Also the two "" you mentioned is there because I used a string literal to
escape the quotes. For exanmple

str = @"This is ""a''" test"
and
str = "This is \"a\" test"

are equivalent.

BTW I changed my expression to the second form and it still goes inside
infinite loop!
Thanks
--
-jojobar
"Steven Cheng[MSFT]" wrote:
Hi Jojobar,

Welcome to ASP.NET newsgroup.

As for the regex problem you mentioned, I think you can first test the
regex through the .net regulator tool which is a pure .net developed regex
testing tool:

http://sourceforge.net/project/showf...roup_id=105210

also, from the code you provided, you used the following regex expression:

strReg = @"(<\w+:(.|[\r\n])*?id=""btnComplete"")([^>]+>)";

based on my test, the original regex should be
(<\w+:(.|[\r\n])*?id="btnComplete")([^>]+>) and you use "" to escape " ,
yes?
If so, this will not work in .net because "" is not the correct escape for
" in C#, you may consider use

strReg = "(<\\w+:(.|[\\r\\n])*?id=\"btnComplete\")([^>]+>)" , anyway
manually replace each particular char with the escaped one in C# format.

Hope this helps.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Mar 8 '06 #7
Thank for your followup jojobar,

Really feel a bit suprised. Is this hang behavior occuring both in a
winform application and ASP.NET application? If it's a common issue, I'll
try reproducing and try contacting some other framework guys to see whether
this is an known issue. At least this should be a big problem.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Mar 9 '06 #8
It is happening in winforms program. I suspect this may happen in a console
program too.
--
-jojobar
"Steven Cheng[MSFT]" wrote:
Thank for your followup jojobar,

Really feel a bit suprised. Is this hang behavior occuring both in a
winform application and ASP.NET application? If it's a common issue, I'll
try reproducing and try contacting some other framework guys to see whether
this is an known issue. At least this should be a big problem.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Mar 9 '06 #9
Thanks for your response.

Well, I've perfomed the test through the file you attached on the site and
I managed to reproduce the problem. Actually the "regulator" tool also
somewhat suffers this issue. I agree that there should be something
internally cause this behavior(and the file you provided just fire this
issue). IMO, due to the limitation of our newsgroup support resource, such
kind of issue should be better to be handled by CSS which can leverage
further resource and provide other thorough troubleshooting on this (like
dump analysis). therefore, if you feel this an urgent issue to resolve or
get a workaround, I suggest contact CSS for further assistance.

Thanks for your understanding.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Mar 10 '06 #10
I am not sure how and where to contact css. So I will try to find an
workaround. Thanks for the help. Maybe you can pass this email to the
developer community in MS and this bug can be fixed.

Thanks
--
-jojobar
"Steven Cheng[MSFT]" wrote:
Thanks for your response.

Well, I've perfomed the test through the file you attached on the site and
I managed to reproduce the problem. Actually the "regulator" tool also
somewhat suffers this issue. I agree that there should be something
internally cause this behavior(and the file you provided just fire this
issue). IMO, due to the limitation of our newsgroup support resource, such
kind of issue should be better to be handled by CSS which can leverage
further resource and provide other thorough troubleshooting on this (like
dump analysis). therefore, if you feel this an urgent issue to resolve or
get a workaround, I suggest contact CSS for further assistance.

Thanks for your understanding.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Mar 11 '06 #11
Thanks for your followup.

If necessary, you can contact the CSS through the following link:

http://support.microsoft.com/

Of course, I can help forward this to our internal dicussion group so that
some dev engineer can see this issue. In addition, I also suggest you
posting this to the MSDN product feedback center:

http://lab.msdn.microsoft.com/produc...k/default.aspx

Thanks for your understanding.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Mar 13 '06 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: sathyashrayan | last post by:
Following are the selected thread from the date:30-jan-2005 to 31-jan-2005. I did not use any name because of the subject is important. You can get the original thread by typing the subject...
13
by: blair.bethwaite | last post by:
Hi all, Does anybody know of a module that allows you to enumerate all the strings a particular regular expression describes? Cheers, -Blair
1
by: Bob | last post by:
The below regular express can sometimes cause an infinite loop. Anyone know what could cause this? string RegexSig = @"To:*\s*(?<address>\S+@\S+)*(\s|\S)*did not reach the following recipient"; ...
25
by: Mike | last post by:
I have a regular expression (^(.+)(?=\s*).*\1 ) that results in matches. I would like to get what the actual regular expression is. In other words, when I apply ^(.+)(?=\s*).*\1 to " HEART...
9
by: Kirk | last post by:
Hi All, the following regular expression matching seems to enter in a infinite loop: ################ import re text = ' MSX INTERNATIONAL HOLDINGS ITALIA srl (di seguito MSX ITALIA) una '...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.