<small id='JV3ta'></small><noframes id='JV3ta'>

    1. <i id='JV3ta'><tr id='JV3ta'><dt id='JV3ta'><q id='JV3ta'><span id='JV3ta'><b id='JV3ta'><form id='JV3ta'><ins id='JV3ta'></ins><ul id='JV3ta'></ul><sub id='JV3ta'></sub></form><legend id='JV3ta'></legend><bdo id='JV3ta'><pre id='JV3ta'><center id='JV3ta'></center></pre></bdo></b><th id='JV3ta'></th></span></q></dt></tr></i><div id='JV3ta'><tfoot id='JV3ta'></tfoot><dl id='JV3ta'><fieldset id='JV3ta'></fieldset></dl></div>

    2. <legend id='JV3ta'><style id='JV3ta'><dir id='JV3ta'><q id='JV3ta'></q></dir></style></legend>
      <tfoot id='JV3ta'></tfoot>
      • <bdo id='JV3ta'></bdo><ul id='JV3ta'></ul>

        正确匹配 IDN URL

        时间:2023-09-23
      1. <i id='yY5fs'><tr id='yY5fs'><dt id='yY5fs'><q id='yY5fs'><span id='yY5fs'><b id='yY5fs'><form id='yY5fs'><ins id='yY5fs'></ins><ul id='yY5fs'></ul><sub id='yY5fs'></sub></form><legend id='yY5fs'></legend><bdo id='yY5fs'><pre id='yY5fs'><center id='yY5fs'></center></pre></bdo></b><th id='yY5fs'></th></span></q></dt></tr></i><div id='yY5fs'><tfoot id='yY5fs'></tfoot><dl id='yY5fs'><fieldset id='yY5fs'></fieldset></dl></div>
          <bdo id='yY5fs'></bdo><ul id='yY5fs'></ul>
        • <small id='yY5fs'></small><noframes id='yY5fs'>

            <tfoot id='yY5fs'></tfoot>
                  <legend id='yY5fs'><style id='yY5fs'><dir id='yY5fs'><q id='yY5fs'></q></dir></style></legend>
                    <tbody id='yY5fs'></tbody>
                  本文介绍了正确匹配 IDN URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我需要帮助构建一个可以正确匹配自由文本中的 URL 的正则表达式.

                  • 方案
                    • 以下之一:ftphttphttps(ftps 是协议吗?)
                    • scheme
                      • One of the following: ftp, http, https (is ftps a protocol?)
                      • 支持www子域(支持 IDN)
                      • TLD 的基本过滤(我认为 [a-zA-Z]{2,6} 就足够了)
                      • support for www and sub-domain(s) (with support for IDNs)
                      • basic filtering of TLDs ([a-zA-Z]{2,6} is enough I think)

                      以下是关于子域的信息:

                      Here is what I could find out about sub-domains:

                      子域"表示相对依赖,而不是绝对依赖:例如,wikipedia.org 包括一个org 域的子域,以及en.wikipedia.org 包含一个子域wikipedia.org 域的名称.在理论上,这个细分可以下降到 127 层深,每个 DNS 标签最多可以包含 63 个字符,如只要整个域名不总长度超过 255字符.

                      A "subdomain" expresses relative dependence, not absolute dependence: for example, wikipedia.org comprises a subdomain of the org domain, and en.wikipedia.org comprises a subdomain of the domain wikipedia.org. In theory, this subdivision can go down to 127 levels deep, and each DNS label can contain up to 63 characters, as long as the whole domain name does not exceed a total length of 255 characters.

                      关于域名本身,我找不到任何可靠的来源,但我认为非 IDN 的正则表达式(我不确定如何编写 IDN 兼容版本)类似于:

                      Regarding the domain name itself I couldn't find any reliable source but I think the regular expression for non-IDNs (I'm not sure how to write a IDN compatible version) is something like:

                      [0-9a-zA-Z][0-9a-zA-Z-]{2,62}
                      

                      有人能帮我解决这个正则表达式或给我指明一个好的方向吗?

                      推荐答案

                      因 Daring Fireball 成名的 John Gruber,拥有 最近的一篇文章 详细介绍了他对一个良好的 URL 识别正则表达式字符串的追求.他想出了这个:

                      John Gruber, of Daring Fireball fame, had a post recently that detailed his quest for a good URL-recognizing regex string. What he came up with was this:

                      <代码>(([w-]+://?|www[.])[^s()<>]+(?:([wd]+)|([^[:punct:]s]|/)))

                      这显然也适用于包含 Unicode 的 URL.您需要对其稍作修改以获得您正在寻找的其余内容——方案、用户名、密码等. Alan Storm 写了一篇解释 Gruber 的正则表达式模式的文章,我绝对需要它(正则表达式是如此写一次,没有线索,如何再读一次!).

                      Which apparently does OK with Unicode-containing URLs, as well. You'd need to do the slight modification to it to get the rest of what you're looking for -- the scheme, username, password, etc. Alan Storm wrote a piece explaining Gruber's regex pattern, which I definitely needed (regex is so write-once-have-no-clue-how-to-read-ever-again!).

                      这篇关于正确匹配 IDN URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:PHP 或基于 PHP 的 Web 框架是有状态的还是无状态的? 下一篇:PHP REGEX:从 URL 获取域

                  相关文章

                    <bdo id='ar1In'></bdo><ul id='ar1In'></ul>
                  1. <i id='ar1In'><tr id='ar1In'><dt id='ar1In'><q id='ar1In'><span id='ar1In'><b id='ar1In'><form id='ar1In'><ins id='ar1In'></ins><ul id='ar1In'></ul><sub id='ar1In'></sub></form><legend id='ar1In'></legend><bdo id='ar1In'><pre id='ar1In'><center id='ar1In'></center></pre></bdo></b><th id='ar1In'></th></span></q></dt></tr></i><div id='ar1In'><tfoot id='ar1In'></tfoot><dl id='ar1In'><fieldset id='ar1In'></fieldset></dl></div>

                      <small id='ar1In'></small><noframes id='ar1In'>

                    1. <legend id='ar1In'><style id='ar1In'><dir id='ar1In'><q id='ar1In'></q></dir></style></legend>

                      <tfoot id='ar1In'></tfoot>