I am trying to remove the brackets and 'url' from a string similar to this:
url('http://www.stackoverflow.com');
So it would just leave 'http://www.stackoverflow.com'
The furthest I have got to getting this working is
var myvar = url('http://www.stackoverflow.com');
myvar = myvar.replace(/[url()]/g, '');
But obviously this would mean that any 'u', 'r', or 'l' would be removed from the actual domain.
I guess the answer would be to only remove the first instance of each of the characters.
Use capturing group.
var string = "url('http://www.stackoverflow.com')";
var url = string.replace(/\burl\('([^()]*)'\)/g, "$1")
document.write(url)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With