积极答复者
.net正则表达式 函数计算超时

问题
答案
-
其实像常用的正则表达式,比如电话号码,邮箱地址,URL地址,微软都提供了。在RegularExpressionValidator控件的ValidationExpression属性中有。默认的邮箱正则是:
\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*
正常用这些默认的就可以了。当然这些默认的并不是唯一的写法,可以有很多种写法,每一种写法的效率也可能都不一样。你需要做的就是避免误匹配,漏匹配,语法错误等。
为了避免错误的正则表达式计算时间过长,影响程序运行,可以对正则表达式设置一个超时时间:
Regex.Matches 方法 (String, String, RegexOptions, TimeSpan)
更多关于正则表达式的内容,请参考这篇文章:
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey.- 已编辑 CaillenModerator 2013年10月18日 1:37 edit
- 已标记为答案 icy jiang 2013年10月21日 1:50
全部回复
-
你好:
这个正则表达式有问题,用下面这个不会出现这种错误:
^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$
请尝试一下。We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey. -
其实像常用的正则表达式,比如电话号码,邮箱地址,URL地址,微软都提供了。在RegularExpressionValidator控件的ValidationExpression属性中有。默认的邮箱正则是:
\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*
正常用这些默认的就可以了。当然这些默认的并不是唯一的写法,可以有很多种写法,每一种写法的效率也可能都不一样。你需要做的就是避免误匹配,漏匹配,语法错误等。
为了避免错误的正则表达式计算时间过长,影响程序运行,可以对正则表达式设置一个超时时间:
Regex.Matches 方法 (String, String, RegexOptions, TimeSpan)
更多关于正则表达式的内容,请参考这篇文章:
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey.- 已编辑 CaillenModerator 2013年10月18日 1:37 edit
- 已标记为答案 icy jiang 2013年10月21日 1:50