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"'
.
精彩评论