Php regexp for country domains

Thare - these are new country domains and TLDs, such as http: //president.rf/ "- for the domains of the Russian Federation or http: // example. 新加坡 for Singapore ...

Is there a regex for checking these domains?

<y> I found this: What is the best regular expression to check if a string is a valid URL?

But when I try to use one of the expressions listed there - PHP gets redundancy :)

preg_match(): Compilation failed: character value in \x{...} sequence is too large at offset 81

PS

1) The last part was solved using @OmnipotentEntity

2) But the main problem - international domain validation - still exists because the regexp example does not validate correctly.

+3
source share
2 answers

No, there is no regular expression for checking these domains. Each TLD has different rules by which Unicode code points are valid within their IDN (if any). You will need a very large lookup table that needs to be updated to know which specific characters are legal.

In addition, there are rules on whether characters from left to right and characters from right to left can be combined within the same DNS label.

By the way, the RFCs mentioned in other comments are out of date. The recently approved kit is RFC 5890 - 5895.

+2
source

Use the “u” modifier to match Unicode characters. In the above example, only the "i" modifier is used.

+3
source

Source: https://habr.com/ru/post/1778135/


All Articles