next.js/packages/next/src/next-devtools/dev-overlay/utils/parse-url-from-text.ts
parse-url-from-text.ts14 lines333 B
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
}
Quest for Codev2.0.0
/
SIGN IN