vs.net 2005正则表达式无限循环... [英] vs.net 2005 regular expression infinite loop...

查看:71
本文介绍了vs.net 2005正则表达式无限循环...的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个aspx文件(下面显示的代码段):


=======

< td class =" light- M1" ID = QUOT; rwCompleteButton" runat =" server">< br />

< asp:ImageButton CssClass =" clear-m1" runat =" server"

CommandName =" Complete" ID = QUOT; btnComplete" />


< asp:ImageButton CssClass =" clear-m1" runat =" server"

CommandName ="删除" ID = QUOT; btnDelete" />

< / td>

=======


和以下.cs文件到执行(下面的代码段)


========

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

reg = new Regex(strReg);

if(!reg.IsMatch(uiStr))

{

blah ... blah ...

}

========


上面的if语句将进入无限循环。但是,当我在Expresso(在vs.net 2003中编写的第三方工具)上尝试

表达式时,它匹配

就好了。


有什么想法吗?

-

-jojobar

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

推荐答案

抱歉忘了提到我在执行此代码之前首先在uiStr

中读取aspx文件。


谢谢

-

-jojobar

" jojobar"写道:
sorry forgot to mention that I am first reading the aspx file in the uiStr
before executing this code.

Thanks
--
-jojobar
"jojobar" wrote:
我有一个aspx文件(下面显示的代码段):

=======
< td class =" ;光-M1" ID = QUOT; rwCompleteButton" runat =" server">< br />
< asp:ImageButton CssClass =" clear-m1" runat =" server"
CommandName =" Complete" ID = QUOT; btnComplete" />

< asp:ImageButton CssClass =" clear-m1" runat =" server"
CommandName ="删除" ID = QUOT; btnDelete" />
< / td>
=======

以及要执行的以下.cs文件(下面的代码段)

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

上面的if语句将进入无限循环。但是,当我在Expresso(在vs.net 2003中编写的第三方工具)上尝试
表达时,它匹配
就好了。

任何想法?
- -
-jojobar
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



您好Jojobar,


欢迎使用ASP.NET新闻组。 />

至于你提到的正则表达式问题,我认为你可以先通过.net调节器工具测试

正则表达式。这是一个纯粹的.net开发的正则表达式

测试工具:

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


,根据您提供的代码,您使用了以下正则表达式:


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


根据我的测试,原始的正则表达式应该是

(< \w + :(。 ?| [\r\\\
])* ID = QUOT; BT nComplete)([^>] +>)并使用"逃避,

是吗?

如果是这样,这在.net中不起作用,因为"是不是正确的逃避

"在C#中,你可以考虑使用


strReg ="(< \\\\ + :(。| [\\\\\\ n])*? ID = \" btnComplete\")([^>] +>)" ,无论如何

手动用C#格式的转义字符替换每个特定字符。


希望这会有所帮助。


问候,


Steven Cheng

微软在线支持


安全! www.microsoft.com/security

(此帖子按原样提供,不作任何保证,并且不授予

权利。)

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.)


Hello Steven,


谢谢你的时间。我用一个名为expresso的工具测试了它,这是一个更好的正则表达式评估工具。




另外两个&bt。你提到的是因为我使用字符串文字

来逃避引号。例如


str = @"这是" a'''''测试



str ="这是\a \"测试


是等价的。


BTW我将表情改为第二种形式,它仍然在里面

无限循环!

谢谢

-

-jojobar

" Steven Cheng [MSFT]"写道:
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:
嗨Jojobar,

欢迎来到ASP.NET新闻组。

关于你提到的正则表达式问题,我认为你可以先通过.net调节工具测试
正则表达式。这是一个纯粹的.net开发的正则表达式测试工具:

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

另外,根据您提供的代码,您使用了以下正则表达式:

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

根据我的测试,原始的正则表达式应该是
(< \w + :(。| [\\\\ n])*?id =" btnComplete")([^>] +>)并使用"逃避,
是吗?
如果是这样,这将无法在.net中使用,因为"对于
而言,这不是正确的逃避在C#中,您可以考虑使用

strReg ="(< \\\\ + :(。| [\\\\\\ n])*?id = \ " btnComplete\")([^>] +>)" ,无论如何
用C#格式的转义手动替换每个特定的字符。

希望这会有所帮助。

问候,

史蒂文Cheng
Microsoft在线支持

获得安全! www.microsoft.com/security
(此帖已提供按原样,没有保证,也没有赋予
权利。)
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.)



这篇关于vs.net 2005正则表达式无限循环...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆