0

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.

2 Answers2

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

0

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
  • 56
  • 3