特定域的DNS主机名正则及时超时
我有
^\*|^(\*\.)?((xn\-\-)?_?[a-zA-Z0-9]+([\/\-_]*[a-zA-Z0-9]+)*_?(((\.xn\-\-)|\.)[\-_]?[a-zA-Z0-9]+([\/_\-]*[a-zA-Z0-9]{1,}){0,})*\_?\.?)?(((xn\-\-)?_?[a-zA-Z0-9]+(((\.xn\-\-)?|[\-\._])[a-zA-Z0-9]+)*\.)*(xn\-\-)?[a-zA-Z0-9]{2,})?\.?$
这个正则结果导致以下主机名的超时:
hjksdhfkjshdkjfhsjkdddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddfs._
可以帮助解决此问题。
I have
^\*|^(\*\.)?((xn\-\-)?_?[a-zA-Z0-9]+([\/\-_]*[a-zA-Z0-9]+)*_?(((\.xn\-\-)|\.)[\-_]?[a-zA-Z0-9]+([\/_\-]*[a-zA-Z0-9]{1,}){0,})*\_?\.?)?(((xn\-\-)?_?[a-zA-Z0-9]+(((\.xn\-\-)?|[\-\._])[a-zA-Z0-9]+)*\.)*(xn\-\-)?[a-zA-Z0-9]{2,})?\.?$
This regex results in a timeout for the following Hostname:
hjksdhfkjshdkjfhsjkdddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddfs._
Can any one please help fixing this issue.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要使用
regex demo 。
注释:
([\/\ - _]*[A-ZA-Z0-9]+)*
是一个常见的错误,量化组中的一个部分是可选的另一个是必须的,在这些情况下,请检查左侧上下文并相应地修复。在这里,由于之前有一个[A-ZA-Z0-9]+
,因此您需要使用+
而不是*
in oference量化的组,即([/_-]+[a-za-z0-9]+)((\。xn \ - \ - \ - )?| [\ - \ ._ ])
是可选的,虽然必须是强制性的xn \ - \ -
witxn-
+
{0,}
- 与*
相同。You need to use
See the regex demo.
Notes:
([\/\-_]*[a-zA-Z0-9]+)*
is a common error where one part in the quantified group is optional and the other is obligatory, in these cases, check the left-hand context and fix accordingly. Here, since there is a[a-zA-Z0-9]+
right before, so you need to use+
instead of*
inside the quantified group, i.e. ([/_-]+[a-zA-Z0-9]+)*`[a-zA-Z0-9]+(((\.xn\-\-)?|[\-\._])[a-zA-Z0-9]+)*
where((\.xn\-\-)?|[\-\._])
is optional, while it must be obligatoryxn\-\-
must be replaced witxn--
{1,}
- is the same as+
{0,}
- is the same as*
.