My text is something like:
<a href="http://example.com/test this now">Stuff</a>
More stuff
<a href="http://example.com/more?stuff goes here">more</a>
I want to replace what's inside the href
with a function that will URL Encode just the URL portion.
How would I go about this?
UPDATE Here's what I've tried:
postdata.comment.content = postdata.comment.content.replace(/href=\"(.+?)\"/g, function(match, p1) {
return encodeURI(p1);
});
Does not do what I would have hoped.
Expected result is:
<a href="http%3A%2F%2Fexample.com%2Ftest%20this%20now">Stuff</a>
More stuff
<a href="http%3A%2F%2Fexample.com%2Fmore%3Fstuff%20goes%20here">more</a>