Need Regex to Delete HTML attribute
-
I would like to be able to search (and delete) all occurrences of an HTML attribute. for my example, I want to delete the “TITLE” attribute and its value.
In my text file i have …
<p> <a href="hhhh" title="something">xxx</a> <a href="hhhh" title="link #2">xxx</a> </p>
Using a RegEx expression, I want to search and find both “TITLE” attributes, (including the equal sign and quote marks) …
title=“something” AND title=“link #2”
Please help me!
-
@Ron-Ball-0 said in Need Regex to Delete HTML attribute:
title=“something” AND title=“link #2”
You haven’t explained it very well. If the text is exactly what you show then just use the replace function with search mode normal. There is no need for a regex.
If on the other hand “something” could be anything and “link #2” also anything please advise us so.
Terry
-
@Terry-R Sorry, yes, the values between the quotes can be anything … numbers, letters, a mix, etc. anything except another quote! And I actually have hundreds of links in my file to “clean” … each one has a different “TITLE”.
-
@Ron-Ball-0 ,
Since you’ve clarified, you can try this regex to find and then delete the contents. Mind you, the html will still be there, but the actual thing you asked for, will not be.Find What =
(title=".*")
Replace With = blank
Search Mode = REGULAR EXPRESSION
Dot Matches Newline = NOT CHECKEDHere’s a screenshot of what it looks like working. The first example one I found in the search, I replaced with the empty replace, and you see the result. The second example is still intact since I didn’t select to replace it, yet.
-
@Lycan-Thrope That is perfect! I can’t believe it was so small … I’ve been searching and trying so many different things.
-
Lycan-Thrope’s response is adequate for your needs as stated, and has the added bonus of being (probably) fast to execute and easy to understand.
But if you’re curious, here’s an alternative that minimizes side-effects:
replace(<a[^>]*?)\s*title\s*=\s*".*?"([^>]*?>)
with\1\2
.Before:
<a href="fjoenr" title="oenrwn"><i title="eorn">eron</i></a> <a title = "eroeno">foenfeonf title="eoeno"</a> <p>title="Ereoneorn"</p> <a href="eoenoen"></a>title="eoenon" <a title="eoenon" href="eoenroenro">""</a>
After:
<a href="fjoenr"><i title="eorn">eron</i></a> <a>foenfeonf title="eoeno"</a> <p>title="Ereoneorn"</p> <a href="eoenoen"></a>title="eoenon" <a href="eoenroenro">""</a>