How to remove a link from a string in javascript?

5

I would like to know how I can do to remove the link from a string in javascript.

str = "hey olha isso http://google.com.br, legal né?"
var test = str.description.replace(/.*?:///g, "");

Expected result:

  

Hey look at this, cool huh?

    
asked by anonymous 28.08.2015 / 20:21

2 answers

4

You can use this regular expression.

var urlPattern = /(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?/g;
var textoComUrl = "hey olha isso http://google.com.br/, legal né?";
var textoSemUrl = textoComUrl.replace(urlPattern, "");
console.log(textoSemUrl);
    
28.08.2015 / 21:13
4
var test = test.description.replace(/.*?:\/\//g, "");
    
28.08.2015 / 20:24