0

I've been browsing the net for solutions but the one's I got is always only with when the user only inputs the link and not in a sentence/paragraph.

I want to convert the link of a youtube video (which is currently a string) to a link. for example:

Watch this it's good! https://www.youtube.com/watch?v=<YT_ID_HERE> to

Watch this it's good! <a href="https://www.youtube.com/watch?v=<YT_ID_HERE>">https://www.youtube.com/watch?v=<YT_ID_HERE></a>

I've found one but the problem to that is when the user pasted 2 links.

I'm making a simple chat application for learning purposes. I'm also using the Next.js.

I want a way, plugin or a package to do this but I prefer the "way" cause' I will eventually use the link to generate an iframe and use the link there to embed the video.

EDIT: I want to it to return the original value but with the youtube link/s wrapped in an <a> tag.

Marcus
  • 57
  • 8

1 Answers1

1

/https:\/\/www.[\/]*[A-z0-9.\/?=<>]*[\s]/gm

For : watch this https://www.youtube.com/watch?v=<YT_ID_HERE> hello world

Matches: https://www.youtube.com/watch?v=<YT_ID_HERE>

This is a great regex writing tool

Francis Leigh
  • 1,870
  • 10
  • 25