I'm using a jquery url shortener (https://github.com/hayageek/jQuery-URL-shortener), and I'm trying to make it so when the jquery returns the shortened url it will replace the original url in the textarea. My problem is that the .replace() doesn't seem to be working here:
$("#button").click(function () {
regex = /(https?:\/\/(?:www\.|(?!www))[^\s\.]+\.[^\s]{2,}|www\.[^\s]+\.[^\s]{2,})/g ;
var longUrlLink = $("#textarea").val().match(regex);
jQuery.urlShortener({
longUrl: longUrlLink,
success: function (shortUrl) {
$("#textarea").val().replace(longUrlLink, shortUrl);
}
});
});
The regex works fine, and shortUrl is is being returned fine, so the problem must lie with how I've written then last line, but I cannot seem to get it to work.
Any help is greatly appreciated.
shortUrlin your$('#textarea').val()it should automatically overwrite it --$("#textarea").val(shortUrl);$('#textarea').val(shortUrl);...