File size: 333 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
export function parseUrlFromText(
  text: string,
  matcherFunc?: (text: string) => boolean
): string[] {
  const linkRegex = /https?:\/\/[^\s/$.?#].[^\s)'"]*/gi
  const links = Array.from(text.matchAll(linkRegex), (match) => match[0])

  if (matcherFunc) {
    return links.filter((link) => matcherFunc(link))
  }

  return links
}