how to detect and get url on string javascript?
example :
var string = "hei dude, check this link http:://google.com and http:://youtube.com"
how to get result like this from my string :
var result = ["http:://google.com", "http:://youtube.com"]
how do that?
If you want to find a webpage where one term appears in the text of that page and another term appears elsewhere on the page, like the title or URL, then type in that first term followed by intext: followed immediately by the other term.
You input has double ::
after http
. Not sure if it intentional. If it is then use:
var matches = string.match(/\bhttps?::\/\/\S+/gi);
If only one :
is needed then use:
var matches = string.match(/\bhttps?:\/\/\S+/gi);
RegEx Demo
const string = "hei dude, check this link http:://google.com and http:://youtube.com"
const matches = string.match(/\bhttp?::\/\/\S+/gi);
console.log(matches);
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