1

I have been looking for a way to parse URL from a string. My current goal is to parse

https://example.com/foo.png

from a string like

abcxyz https://example.com/foo.png gibberfish text.

Anyone got a solution or a package that can help me to do the job? Thanks in advance.

  • Does this question help? https://stackoverflow.com/questions/6038061/regular-expression-to-find-urls-within-a-string – svict4 Dec 21 '21 at 07:00
  • @Molda thanks sir, your answer solved my question. –  Dec 21 '21 at 07:22

2 Answers2

1

I recommend this solution. It turns all words into an array and picks out the ones starting with https://

text.split(" ").filter(i => i.startsWith("https://")).toString();
Ven
  • 114
  • 5
0
text = "abcxyz https://example.com/foo.png gibberfish text."
console.log(text.split(" ")[1])

.split() splits the string at spaces into an array of words.

You can refer: https://www.w3schools.com/jsref/jsref_split.asp