![]() |
![]() |
![]() |
||||
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. |
![]() ![]() |
|
Discuss what's fucking going on, and which programs are best and worst. One-time "program" announcements from "established" webmasters are allowed. |
|
Thread Tools |
![]() |
#1 |
Too lazy to set a custom title
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 |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#2 |
Totally Borked
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 |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#3 |
Confirmed User
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 |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#4 |
Confirmed User
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 |
![]() |
![]() ![]() ![]() ![]() ![]() |