473,772 Members | 2,272 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

vs.net 2005 regular expression infinite loop...

I have a aspx file (snippet shown below):

=======
<td class="light-m1" id="rwCompleteB utton" runat="server"> <br/>
<asp:ImageButto n CssClass="clear-m1" runat="server"
CommandName="Co mplete" ID="btnComplete " />

<asp:ImageButto n CssClass="clear-m1" runat="server"
CommandName="De lete" ID="btnDelete" />
</td>
=======

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

========
strReg = @"(<\w+:(.|[\r\n])*?id=""btnComp lete"")([^>]+>)";
reg = new Regex(strReg);
if (!reg.IsMatch(u iStr))
{
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 1753
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="rwCompleteB utton" runat="server"> <br/>
<asp:ImageButto n CssClass="clear-m1" runat="server"
CommandName="Co mplete" ID="btnComplete " />

<asp:ImageButto n CssClass="clear-m1" runat="server"
CommandName="De lete" ID="btnDelete" />
</td>
=======

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

========
strReg = @"(<\w+:(.|[\r\n])*?id=""btnComp lete"")([^>]+>)";
reg = new Regex(strReg);
if (!reg.IsMatch(u iStr))
{
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=""btnComp lete"")([^>]+>)";

based on my test, the original regex should be
(<\w+:(.|[\r\n])*?id="btnCompl ete")([^>]+>) 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=\"btnComp lete\")([^>]+>)" , 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=""btnComp lete"")([^>]+>)";

based on my test, the original regex should be
(<\w+:(.|[\r\n])*?id="btnCompl ete")([^>]+>) 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=\"btnComp lete\")([^>]+>)" , 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=\"btnComp lete\")([^>]+>)";

MatchCollection matchs = Regex.Matches(d oc, regex, RegexOptions.Co mpiled |
RegexOptions.Ig noreCase);

MessageBox.Show (matchs.Count.T oString());
=============== =======

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=\"btnComp lete\")([^>]+>)";

MatchCollection matchs = Regex.Matches(d oc, regex, RegexOptions.Co mpiled |
RegexOptions.Ig noreCase);

MessageBox.Show (matchs.Count.T oString());
=============== =======

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.Re adTextFile("tas kcontrol.ascx") ;

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

MatchCollection matchs = Regex.Matches(u iStr, regex, RegexOptions.Co mpiled
| RegexOptions.Ig noreCase);

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.as cx 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=""btnComp lete"")([^>]+>)";

based on my test, the original regex should be
(<\w+:(.|[\r\n])*?id="btnCompl ete")([^>]+>) 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=\"btnComp lete\")([^>]+>)" , 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

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

Similar topics

6
2138
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 "string" in google comp.lang.c archives.Hope this helps.Hope I am not bothering any one. am I? =================================Start=========================== subject: Return to Start of Line? Question: I'd like printf, the next printf, to return...
13
2212
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
2554
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"; Also shouldn't the framework have some type of loop protection? This will run forever. Bob
25
5167
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 (CONDUCTION DEFECT) 37.33/2 HEART (CONDUCTION DEFECT) WITH CATHETER 37.34/2 " the expression is "HEART (CONDUCTION DEFECT)". How do I gain access to the expression (not the matches) at runtime? Thanks, Mike
9
1959
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 ' re.findall('*((?:*+*)+\s**\s*(?: *+*\s*)*)(*)$', text)
0
10261
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10104
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10038
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9912
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6715
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5482
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4007
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3609
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2850
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.