开发者

ASP.net - Regular Expression to add an attribute

开发者 https://www.devze.com 2023-01-20 00:27 出处:网络
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 thetag.

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>


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

0

精彩评论

暂无评论...
验证码 换一张
取 消