ASP.net - 正则表达式添加属性

发布于 2024-09-28 08:36:09 字数 775 浏览 0 评论 0原文

我需要使用正则表达式找到最佳解决方案,以查找 HTML 块内的 URL 并在标签内添加新属性 Name="true"。

下面是一个 HTML 示例(可以包含嵌入的 JS),我只需要将新属性 Name="true" 添加到任何 URL,并且不会影响任何嵌入的 JS 文件。

HTML 示例:

<HTML>
    <a href="abc.aspx">
    <a href="abc.aspx">
    <a href="abc.aspx">

    <script type="javascript">
    function{
    if("somefile.aspx")
    {
    do something...
    }
    }
    </script>
</HTML>

预期 HTML:

<HTML>
    <a href="abc.aspx" Name="true">
    <a href="abc.aspx" Name="true">
    <a href="abc.aspx" Name="true">

    <script type="javascript">
    function{
    if("somefile.aspx")
    {
    do something...
    }
    }
    </script>
</HTML>

I need to find the most optimal solution using Regex to find URL's inside a block of HTML and add a new attribute Name="true" inside the tag.

Below is an example of HTML (which can contain embedded JS), I just need to add the new attribute Name="true" to any URL and NOT effect any embedded JS file.

Example HTML :

<HTML>
    <a href="abc.aspx">
    <a href="abc.aspx">
    <a href="abc.aspx">

    <script type="javascript">
    function{
    if("somefile.aspx")
    {
    do something...
    }
    }
    </script>
</HTML>

Expected HTML :

<HTML>
    <a href="abc.aspx" Name="true">
    <a href="abc.aspx" Name="true">
    <a href="abc.aspx" Name="true">

    <script type="javascript">
    function{
    if("somefile.aspx")
    {
    do something...
    }
    }
    </script>
</HTML>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

盗琴音 2024-10-05 08:36:09

/href="([_allowed_characters_in_URL_]+)"/ 替换为 'href="$1" Name="true"'

Replace /href="([_allowed_characters_in_URL_]+)"/ by 'href="$1" Name="true"'.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文