Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7511801
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T23:40:03+00:00 2026-05-29T23:40:03+00:00

I have a PHP regular expression I’m using to get the YouTube video code

  • 0

I have a PHP regular expression I’m using to get the YouTube video code out of a URL.

I’d love to match this with a client-side regular expression in JavaScript. Can anyone tell me how to convert the following PHP regex to JavaScript?

preg_match("#(?<=v=)[a-zA-Z0-9-]+(?=&)|(?<=v\/)[^&\n]+(?=\?)|(?<=embed/)[^&\n]+|(?<=v=)[^&\n]+|(?<=youtu.be/)[^&\‌​n]+#", $url, $matches);

Much appreciated, thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T23:40:05+00:00Added an answer on May 29, 2026 at 11:40 pm

    I think the only problem is to get rid of the lookbehind assertions (?<=...), they are not supported in Javascript.

    The advantage of them is, you can use them to ensure that a pattern is before something, but they are NOT included in the match.

    So, you need to remove them, means change (?<=v=)[a-zA-Z0-9-]+(?=&) to v=[a-zA-Z0-9-]+(?=&), but now your match starts with “v=”.

    If you just need to validate and don’t need the matched part, then its fine, you are done.

    But if you need the part after v= then put instead the needed pattern into a capturing group and continue working with those captured values.

    v=([a-zA-Z0-9-]+)(?=&)
    

    You will then find the matched substring in $1 for the first group, $2 for the second, $3 …

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this regular expression: ([http://some.url.com/index.php?showtopic=\]*)([0-9]+(?:\.[0-9]*)?) its for extracting links to topics from forum
I have a regular expression to match usernames (which functions in PHP using preg_match
I am trying to fix a regular expression i have been using in php
I have the following line: <?php echo $this->__(mytext);?>somesometext)moretext and I need a regular expression
I am trying to get commented strings in my code using regular expression in
I have a regular expression in my PHP script like this: /(\b$term|$term\b)(?!([^<]+)?>)/iu This matches
I have written following regular expression /^[A-Za-z0-9-_\s]*$/ in PHP which allows numbers, letters, spaces,
I have a little problem with my regular expression, that I use in PHP.
I have a regular expression in PHP that looks for the date in the
I'd like to have a regular expression in PHP like /A.B./i but the random

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.