checkopenport
checkopenport

Reputation: 121

Preg_matche youtube id issue

I'm working on a small php script. I have used preg_match to grab youtube id from a long text. Any way i'm using this code :

preg_match('~/v/([0-9a-z_]+)~i', $text, $matches)

The code work perfectly but he dont grab ids which containt "-".

Upvotes: 0

Views: 32

Answers (1)

Tchoupi
Tchoupi

Reputation: 14691

You don't have a - in your regular expression, it should be:

preg_match('~/v/([0-9a-z_\-]+)~i', $text, $matches)

Upvotes: 1

Related Questions