Skip to content

Commit

Permalink
replaced youtube regex with regex found on https://regexr.com/3dj5t, … (
Browse files Browse the repository at this point in the history
#4645)

* replaced youtube regex with regex found on https://regexr.com/3dj5t, fixes #4560

* adds support for music. subdomain

* Create dry-ghosts-wash.md

---------

Co-authored-by: bdbch <[email protected]>
  • Loading branch information
janthurau and bdbch authored Dec 5, 2024
1 parent a0d2f28 commit a8d37ee
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/dry-ghosts-wash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@tiptap/extension-youtube": patch
---

Improved youtube regexes with more solid variants handling more subdomains and properties
4 changes: 2 additions & 2 deletions packages/extension-youtube/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export const YOUTUBE_REGEX = /^(https?:\/\/)?(www\.|music\.)?(youtube\.com|youtu\.be|youtube-nocookie\.com)\/(?!channel\/)(?!@)(.+)?$/
export const YOUTUBE_REGEX_GLOBAL = /^(https?:\/\/)?(www\.|music\.)?(youtube\.com|youtu\.be)\/(?!channel\/)(?!@)(.+)?$/g
export const YOUTUBE_REGEX = /^((?:https?:)?\/\/)?((?:www|m|music)\.)?((?:youtube\.com|youtu.be|youtube-nocookie\.com))(\/(?:[\w-]+\?v=|embed\/|v\/)?)([\w-]+)(\S+)?$/
export const YOUTUBE_REGEX_GLOBAL = /^((?:https?:)?\/\/)?((?:www|m|music)\.)?((?:youtube\.com|youtu.be|youtube-nocookie\.com))(\/(?:[\w-]+\?v=|embed\/|v\/)?)([\w-]+)(\S+)?$/g

export const isValidYoutubeUrl = (url: string) => {
return url.match(YOUTUBE_REGEX)
Expand Down

0 comments on commit a8d37ee

Please sign in to comment.