I am trying to match a url in four different situations:
With no attributes
<a href="example.com/reviews/audi/a6/">Link without other attr</a>
With other attributes
<a href="example.com/reviews/audi/a6/" class="button">Link with other attr</a>
With no standard href
<span data-link="example.com/reviews/audi/a6/">Link with no href</a>
Just the URL
example.com/reviews/audi/a6
In all of them I always want to do the same, swap reviews at the end without an extra /
I am using this regex to account for the ones that have another attr by identifing the space after the "
("example\.com)\/(reviews|used-cars)\/(.*[^\/$])(\/?)(" )
But then if it ends in ">
it messes up and matches end of class
("example\.com)\/(reviews|used-cars)\/(.*[^\/$])(\/?)(">)