Notices
Computer & Technology Related Post here for help and discussion of computing and related technology. Internet, TVs, phones, consoles, computers, tablets and any other gadgets.

Regular Expression help

Thread Tools
 
Search this Thread
 
Old Jun 23, 2009 | 02:25 PM
  #1  
Markus's Avatar
Markus
Thread Starter
Scooby Regular
25 Year Member
 
Joined: Mar 1999
Posts: 25,080
Likes: 0
From: The Great White North
Default Regular Expression help

Hello all,
I need a bit of help with unix regular expressions and I'm far from knowledgeable on this.

I have the following regular expression:

Code:
[http://]*[a-z]*?[\.]?youtube\.[a-z]*?/watch\?v=([A-Z0-9._%-]*)[&\w;=\+_\-]*
It's essentially parsing a url and pulling bits of information out of it to create the following:

Code:
<object width="$ameinfo[width]" height="$ameinfo[height]">
<param name=''movie'' value="http://www.youtube.com/v/$p1&ap=%2526fmt%3D18&fs=1"></param>
<param name="allowFullScreen" value="true"></param>
<embed src="http://www.youtube.com/v/$p1&ap=%2526fmt%3D18&fs=1" type="application/x-shockwave-flash" allowfullscreen="true" width="$ameinfo[width]" height="$ameinfo[height]" wmode="transparent"></embed></object>
It works perfectly with a url of this format:
Code:
http://www.youtube.com/watch?v=XXXX-XxXXxxX
However the following format of url does not work
Code:
http://www.youtube.com/v/XXXX-XxXXxxX

I am smart enough to see that there is a difference in the URL that the regex isn't handling, but I'm not sure how to go about modifying the existing regex to deal with the second url.

I think it would be a tad complicated, if not impossible, to have a single regex for both urls, but if someone knows how to do that, great. Otherwise, if someone can clue me in to what needs to be changed in the regex to deal with the second url I'd appreciate it.

If someone is really bored they could explain what all the portions of the rexeg command are doing. I'm fairly sure it's splitting the url into portions, and gathering/removing stuff based on certain criteria, for example if a portion of the url is alphanumeric.
Reply
Old Jun 24, 2009 | 12:13 AM
  #2  
RichB's Avatar
RichB
Scooby Regular
 
Joined: Apr 1999
Posts: 3,666
Likes: 0
From: Bore Knee Muff
Default

God I hate regex... They are so complicated but I know they are powerful...
Is your answer not as simple as removing the : "watch\?v=" and replacing with "v/"
[http://]*[a-z]*?[\.]?youtube\.[a-z]*?/v/([A-Z0-9._%-]*)[&\w;=\+_\-]*
Reply
Old Jun 24, 2009 | 12:32 AM
  #3  
Markus's Avatar
Markus
Thread Starter
Scooby Regular
25 Year Member
 
Joined: Mar 1999
Posts: 25,080
Likes: 0
From: The Great White North
Default

That's what I thought and I've tried that, but it does not appear to have the desired result. This is actually part of the AME mod for vBulletin, so it could be doing more behind the scenes, but I don't think so. The idea is it'll parse a url in a post, using the regex and then build the appropriate code to allow the video to be embedded in the page.
Reply
Old Jun 24, 2009 | 02:03 PM
  #4  
RichB's Avatar
RichB
Scooby Regular
 
Joined: Apr 1999
Posts: 3,666
Likes: 0
From: Bore Knee Muff
Default

I used this to see what happened:
Download Reggy for Mac - Visualize what regular expression will match given test string. MacUpdate Mac Editors Software Downloads
It seems to do the same when we use our new version of the expression....
It goes blue when it matches - I dont know
Reply
Old Jun 24, 2009 | 03:53 PM
  #5  
Markus's Avatar
Markus
Thread Starter
Scooby Regular
25 Year Member
 
Joined: Mar 1999
Posts: 25,080
Likes: 0
From: The Great White North
Default

Yeah, I tried some online regex checker thing and it did the same too! Some people think that the problem started with the upgrade to vBulletin 3.8.3, so it's possible that may be the problem. I've posted on the modification's thread so we'll see if there is a response there too.

Thanks for the help
Reply
Related Topics
Thread
Thread Starter
Forum
Replies
Last Post
Wingnuttzz
Member's Gallery
30
Apr 26, 2022 11:15 PM
KAS35RSTI
Subaru
27
Nov 4, 2021 07:12 PM
Sambob
Engine Management and ECU Remapping
41
Nov 27, 2015 07:36 PM
powerwrx
Non Scooby Related
21
Oct 3, 2015 11:31 PM
JonMc
Lighting and Other Electrical
12
Sep 25, 2015 11:34 AM




All times are GMT +1. The time now is 01:35 PM.