简体   繁体   中英

DNS Hostname RegEx Timeout for particular domains

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.

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, ie ([/_-]+[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 * .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM