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

      1. <small id='T1eb9'></small><noframes id='T1eb9'>

          <bdo id='T1eb9'></bdo><ul id='T1eb9'></ul>
        <tfoot id='T1eb9'></tfoot>

        没有 &lt;a&gt; 的正则表达式匹配链接标签

        时间:2023-07-15

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

              <legend id='i1dB5'><style id='i1dB5'><dir id='i1dB5'><q id='i1dB5'></q></dir></style></legend>
                <bdo id='i1dB5'></bdo><ul id='i1dB5'></ul>
                  <tbody id='i1dB5'></tbody>
                  <tfoot id='i1dB5'></tfoot>
                  本文介绍了没有 &lt;a&gt; 的正则表达式匹配链接标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  (http([s]?)://?)(([a-zA-Z0-9]+(.?))+)([a-zA-Z0-9]+((.[a-zA-Z]{2,5}){1,2})((/[a-zA-Z0-9?&=_-~:/?#[]@!$&'()*+,;]*)*)((.[a-zA-Z]{2,5}){0,2}))
                  

                  这是我的正则表达式,它可以很好地匹配字符串中的链接.但我不希望它选择每个链接.如果链接前面有 "></a>,则该链接不应该被数学化.怎么做?

                  This is my regex which is working well for matching the links in the string. But I don't want it to select every link. If a link has "> before it, or </a> after it, that link shouldn't be mathced. How can it be done?

                  这些应该匹配:

                  adasdas http://www.stackoverflow.com asdasas
                  adasdasahttp://www.stackoverflow.com/something asdas
                  

                  这些不应该匹配:

                  adasdas<a href="somelink">           http://www.stackoverflow.com     </a>asdasas
                  adasdasa<a href="somelink">http://www.stackoverflow.com/something</a> asdas
                  

                  为什么我需要这个?:我希望每个链接都可以点击,即使它不在锚标签之间.

                  Why do I need this?: I want every link to be clickable even if it isn't between anchor tags.

                  推荐答案

                  所有关于使用正则表达式解析 html 的免责声明,如果你想使用正则表达式来完成这个任务,这将起作用:

                  With all the disclaimers about using regex to parse html, if you want to use regex for this task, this will work:

                  $regex="~<a.*?</a>(*SKIP)(*F)|http://S+~";
                  

                  参见演示.

                  这个问题是这个问题中解释的技术的经典案例,用于regex-match a pattern, exclude..."

                  This problem is a classic case of the technique explained in this question to "regex-match a pattern, excluding..."

                  交替的左侧|匹配完整的然后故意失败,之后引擎跳到下一个字符串中的位置.右侧匹配 url,我们知道它们是正确的,因为它们与左侧的表达式不匹配.

                  The left side of the alternation | matches complete <a ...tags </a> then deliberately fails, after which the engine skips to the next position in the string. The right side matches the urls, and we know they are the right ones because they were not matched by the expression on the left.

                  我放在右边的 url regex 可以细化,使用任何适合您的需求即可.

                  The url regex I put on the right and can be refined, just use whatever suits your needs.

                  参考

                  • 如何匹配(或替换)模式,除了 s1、s2、s3...
                  • 关于匹配模式的文章,除非...

                  这篇关于没有 &lt;a&gt; 的正则表达式匹配链接标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如何从 .html 页面中提取链接和标题? 下一篇:Preg_match_all <a href

                  相关文章

                • <small id='yudLd'></small><noframes id='yudLd'>

                • <tfoot id='yudLd'></tfoot>

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

                    • <bdo id='yudLd'></bdo><ul id='yudLd'></ul>

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