Welcome to the GoFuckYourself.com - Adult Webmaster Forum forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Post New Thread Reply

Register GFY Rules Calendar Mark Forums Read
Go Back   GoFuckYourself.com - Adult Webmaster Forum > >
Discuss what's fucking going on, and which programs are best and worst. One-time "program" announcements from "established" webmasters are allowed.

 
Thread Tools
Old 09-15-2009, 08:35 AM   #1
fris
Too lazy to set a custom title
 
fris's Avatar
 
Industry Role:
Join Date: Aug 2002
Posts: 55,372
regex nightmare: anyone want to check it?

My youtube wordpress plugin works via

[!youtube]L1BDM1oBRJ8[/youtube!]

I also wanted to be able to do it via

https://youtube.com/watch?v=L1BDM1oBRJ8
https://youtube.com/watch?v=L1BDM1oBRJ8
www.youtube.com/watch?v=L1BDM1oBRJ8
youtube.com/watch?v=L1BDM1oBRJ8
watch?v=L1BDM1oBRJ8
v=L1BDM1oBRJ8
L1BDM1oBRJ8
https://youtube.com/v/L1BDM1oBRJ8

Code:
$regex = "/\[(?:(?:http:\/\/)?(?:www\.)?youtube\.com\/)?(?:(?:watch\?)?v=|v\/)?([a-zA-Z0-9\-\_]{11})(?:&[a-zA-Z0-9\-\_]+=[a-zA-Z0-9\-\_]+)*\]/";
__________________
Since 1999: 69 Adult Industry awards for Best Hosting Company and professional excellence.


WP Stuff
fris is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 09-15-2009, 08:41 AM   #2
borked
Totally Borked
 
borked's Avatar
 
Industry Role:
Join Date: Feb 2005
Posts: 6,284
well, the simplest is to optionally allow each component:

(http:\/\/)?(www\.)?(youtube\.com)?(\/)?(watch\?)?(v=)?([a-zA-Z0-9]{11})

but then this means that any optional component can be left out eg:
http://v=L1BDM1oBRJ8

is valid.
__________________

For coding work - hit me up on andy // borkedcoder // com
(consider figuring out the email as test #1)



All models are wrong, but some are useful. George E.P. Box. p202
borked is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 09-15-2009, 08:42 AM   #3
BestXXXPorn
Confirmed User
 
BestXXXPorn's Avatar
 
Join Date: Jun 2009
Location: Asheville, NC
Posts: 2,277
That should work, it might be a little overkill with all the valid character checking though :P

You could also:

$arr = explode('=', $youTubeURL);

and validate just the portion you want:

$linkCode = $arr[count($arr)-1];

While that wouldn't work with the last case you posted you could just do a:

$youTubeUrl = str_replace('/', '=', $youTubeUrl);

before hand since you don't care what the domain is anyway... It would definitely be much faster than using regex, parsing wise :P
__________________
ICQ: 258-202-811 | Email: eric{at}bestxxxporn.com
BestXXXPorn is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 09-15-2009, 08:51 AM   #4
BestXXXPorn
Confirmed User
 
BestXXXPorn's Avatar
 
Join Date: Jun 2009
Location: Asheville, NC
Posts: 2,277
Running benchmarks on regex (using borked's simplified regex) vs explode (since we're trying to strip the actual value for v...

I show explode method as twice as fast as regex ;)
__________________
ICQ: 258-202-811 | Email: eric{at}bestxxxporn.com
BestXXXPorn is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Post New Thread Reply
Go Back   GoFuckYourself.com - Adult Webmaster Forum > >

Bookmarks
Thread Tools



Advertising inquiries - marketing at gfy dot com

Contact Admin - Advertise - GFY Rules - Top

©2000-, AI Media Network Inc



Powered by vBulletin
Copyright © 2000- Jelsoft Enterprises Limited.