Reputation: 1221
I have a bunch of html files.
I am trying to find all anchor links whose href attribute does not end with slash
For example :-
<a href="/hello">Helllo</a>
This should match
<a href="/hello/">Helllo</a>
This should not match
How do i go on about making the regular expression.
Upvotes: 1
Views: 616
Reputation: 626689
In order to make sure you only collect href
attribute values from <a>
elements, and to make sure you only match the link itself, you can use the following regex:
<a\s[^<>]*href="\K[^"]*?(?<=[^\/])(?=")
Or
<a\s[^<>]*href="\K[^"]*?(?=(?<=[^\/])")
Upvotes: 2
Reputation: 98871
You can try:
Find: href="(.*?[^/])"
Replace with: href="$1/"
Upvotes: 2
Reputation: 1246
Building on hjpotter92's answer...
Find: href="(\S*?[^/])"
Replace: href="$1/"
Upvotes: 3