特定域的DNS主机名正则及时超时

发布于 2025-02-07 03:11:43 字数 537 浏览 3 评论 0原文

我有

^\*|^(\*\.)?((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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

你曾走过我的故事 2025-02-14 03:11:43

您需要使用

^\*|^(\*\.)?((xn--)?_?[a-zA-Z0-9]+([\/_-]+[a-zA-Z0-9]+)*_?(\.(xn--)?[-_]?[a-zA-Z0-9]+([\/_-]+[a-zA-Z0-9]+)*)*_?\.?)?(((xn--)?_?[a-zA-Z0-9]+((\.xn--|[-._])[a-zA-Z0-9]+)*\.)*(xn--)?[a-zA-Z0-9]{2,})?\.?$

regex demo

注释

  • ([\/\ - _]*[A-ZA-Z0-9]+)*是一个常见的错误,量化组中的一个部分是可选的另一个是必须的,在这些情况下,请检查左侧上下文并相应地修复。在这里,由于之前有一个[A-ZA-Z0-9]+,因此您需要使用+而不是* in oference量化的组,即([/_-]+[a-za-z0-9]+)
  • * - )?| [\ - \ ._])[A-ZA-Z0-9]+)*其中((\。xn \ - \ - \ - )?| [\ - \ ._ ])是可选的,虽然必须是强制性的
  • 逃脱字符类外的连字符,但必须替换xn \ - \ - wit xn-
  • <代码> {1,} - 与+
  • {0,} - 与*相同。

You need to use

^\*|^(\*\.)?((xn--)?_?[a-zA-Z0-9]+([\/_-]+[a-zA-Z0-9]+)*_?(\.(xn--)?[-_]?[a-zA-Z0-9]+([\/_-]+[a-zA-Z0-9]+)*)*_?\.?)?(((xn--)?_?[a-zA-Z0-9]+((\.xn--|[-._])[a-zA-Z0-9]+)*\.)*(xn--)?[a-zA-Z0-9]{2,})?\.?$

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]+)*`
  • Same thing with [a-zA-Z0-9]+(((\.xn\-\-)?|[\-\._])[a-zA-Z0-9]+)* where ((\.xn\-\-)?|[\-\._]) is optional, while it must be obligatory
  • Escaping hyphens outside of character classes is useless, xn\-\- must be replaced wit xn--
  • {1,} - is the same as +
  • {0,} - is the same as *.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文