Regular Expressions 101

Community Library Entry

0

Regular Expression
PCRE2 (PHP >=7.3)

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

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 - 2 years ago