Am I doing this Preg_Replace correct? [closed]

I’m trying to shorten a YouTube video to just the ID in a plugin. I have it removing all variations of youtube.com, but when it comes to after the ‘?’, it doesn’t do it. For example, if the YouTube link is:

12345-67890?feature=share

I use this code:

$video_id = preg_replace('/\?.*$/i', '', $video_id);

and it comes back with

12345-67890feature=share

Am I missing something here?

variations of preg_replace.

  • I can’t reproduce the problem. See ideone.com/qnMfq4

    – 

  • The result you show is what you’d get if the regexp were just /\?/

    – 

  • @jeff you must present a minimal reproducible example in your question body. When asking for regex solutions, it is best to offer several sufficiently different sample input strings and your exact desired output.

    – 

Leave a Comment