Consider a string
let a = "I visit google.com often times but.. not amazon.uk"
How to extract google.com and amazon.uk from the string above in JavaScript
Consider a string
let a = "I visit google.com often times but.. not amazon.uk"
How to extract google.com and amazon.uk from the string above in JavaScript
Try this :
let a = "I visit google.com often times but.. not amazon.uk"
a.match(/("[^"]+"|[^"\s]+)/g);
Output:
[
"I",
"visit",
"google.com",
"often",
"times",
"but..",
"not",
"amazon.uk"
]
Here is one way to do it
\s(\w+)(.uk|.com)\b
here is a fiddle link for Javascript
https://jsfiddle.net/y25wz3ae/
https://regex101.com/r/HFyxEJ/1
Result [('google', '.com'), ('amazon', '.uk')]
To solve this problem I've created an API to extract URLs from a string or an array of strings
Base Url -> https://urlsparser.herokuapp.com/
GET https://urlsparser.herokuapp.com/url
For a single string
{
"string" : "More here http://action.mySite.com/trk.php?mclic=P4CAB9542D7F151&urlrv=http%3A%2F%2Fjeu-centerparcs.com%2F%23%21%2F%3Fidfrom%3D8&urlv=517b975385e89dfb8b9689e6c2b4b93d text<br/>And more here http://action.mySite.com/trk.php?mclic=P4CAB9542D7F151&urlrv=http%3A%2F%2Fjeu-centerparcs.com%2F%23%21%2F%3Fidfrom%3D8&urlv=517b975385e89dfb8b9689e6c2b4b93d"
}
For an array of strings
{
"string" : ["string1","string2"....]
}
Screenshot
Advantages