I am trying to pull out all the URLs from a text entered by the user by doing the following but am not able to get the desired result.
let regexp = /^(?:http(s)?:\/\/)?[\w.-]+(?:\.[\w\.-]+)+[\w\-\._~:/?#[\]@!\$&'\(\)\*\+,;=.]+$/igm;
let str = "https://mysleepyhead.com http://skreem.io";
let array = [...str.matchAll(regexp)];
console.log(array);
Desired output would be
Array ['https://mysleepyhead.com', 'http://skreem.io']
^and$anchor to the beginning and end of the line. If the string you're dealing with is composed of multiple possible matches in a single line, don't use those anchors. regex101.com/r/q89Ipv/1 (you also probably want.match, not.matchAll)"https://mysleepyhead.com http://skreem.io".match(/(?:http(s)?:\/\/)?[\w.-]+(?:\.[\w\.-]+)+[\w\-\._~:/?#[\]@!\$&'\(\)\*\+,;=.]+/igm)httpoptional. Maybe you want to make sure the match contains at least one.in it?(?:http(s)?:\/\/)?(?=[a-z])[\w-]+(?:\.[\w-]+)+(?:\/\S*)?or something of the sort