Regular Expressions 101

Community Patterns

Youtube redirect regex

1

Regular Expression
ECMAScript (JavaScript)

/
^(?:http[s]?):(?=\/)\/\/(?:(?:www[.])?youtube[.](?:[^@\/.?#:]+))\/(?:redirect)(?:\?(?:(?=event=(?:[^&#?\/@:]+))event=[^&#?\/@:]+)(?:&(?=redir_token=(?:[a-zA-z0-9]{206}))redir_token=[a-zA-z0-9]{206})?(?:[&][^@#]+)?(?=&q)&q=([^&#?\/@:]+)(?=&)&(?:(?:[^&#?\/@:]*)+))$(?<![#])(?:[^#]*)
/
g

Description

Separate the youtube tracking redirect link to its main companions

Version 1

  • Python
  • PHP

Version 2

  • JavaScript
  • Java
  • PHP
  • C#
  • maybe more

Version 3

  • PHP
  • Java
  • C#
  • Possibly Javascript (with filtering)

Version 4 : Only bracket in return value

  • PHP
  • python
  • Golang
  • Java
  • C#
  • Rust (can work but without support for php)

first inspiration taken from here

Submitted by TS - 5 months ago (Last modified 5 months ago)