Regular Expressions 101

Community Patterns

Community Library Entry

0

Regular Expression
Created·2022-06-26 23:50
Flavor·PCRE2 (PHP)

/
(?:https?:\/\/)?(?:www\.)?youtu(?:be)?\.(?:com|be)(?:\/watch\/?\?v=|\/embed\/|\/shorts\/|\/)(\w+)
/
g
Open regex in editor

Description

Can obtain videoId using

videoId () {
  return this.video_url.match(/(?:https?:\/\/)?(?:www\.)?youtu(?:be)?\.(?:com|be)(?:\/watch\/?\?v=|\/embed\/|\/shorts\/|\/)(\w+)/)[1]
}

Can check if valid Youtube link using

return value.match(/(?:https?://)?(?:www.)?youtu(?:be)?.(?:com|be)(?:/watch/??v=|/embed/|/shorts/|/)(\w+)/)

Submitted by anonymous