Regex Help

Eldorado

Moderator
Staff member
May 7, 2012
990
0
16
So this Sharebees site is bugging me and I know I'm probably makes this more complicated than it needs to be...

...but I'm determined to do it all in regex and hopefully learn regex better :)

So far I've found ShareBees gives their links in at least 2 different javascript portions:

avi's/mp4's
Code:
var s1 = new SWFObject('http://www.sharebees.com/player/player.swf', 'player', '600', '400', '9');
s1.addParam('allowfullscreen', 'true');
s1.addParam('allowscriptaccess', 'always');
s1.addParam('wmode', 'opaque');
s1.addVariable('duration', '');
s1.addVariable('file', 'http://198.143.162.242:182/d/xnf27xt24kfp7yqk6szri2ploqfuaectua5yzlrmcwtsr4grrp4evmqr/video.mp4');
s1.addVariable('image', 'http://198.143.162.242/i/00009/plr1y80ulabw.jpg');
s1.addVariable('provider', 'video');
s1.addVariable('skin', 'http://www.sharebees.com/mmm/grungetape/grungetape.xml');
s1.addVariable('controlbar', 'over');
s1.write('flvplayer');
mkv's
Code:
document.write('<object id="ie_vid"classid="clsid:67DABFBF-D0AB-41fa-9C46-CC0F21721616"width="600"height="400"codebase="http://go.divx.com/plugin/DivXBrowserPlugin.cab"><param name="custommode"value="Stage6"/><param name="wmode"value="transparent"/><param name="previewImage"value="http://108.178.29.46/i/00009/kpw0suyotby3.jpg"/><param name="allowContextMenu"value="false"><param name="bannerEnabled"value="false"/><param name="previewMessage"value="Play"/><param name="autoPlay"value="false"/><param name="src"value="http://108.178.29.46:182/d/xbfz3xt24kfp7yqk6szq65poovti3ox3bzetkpzz47y4taajbjb5h3hl/video.mkv"/><embed id="np_vid"type="video/divx"src="http://108.178.29.46:182/d/xbfz3xt24kfp7yqk6szq65poovti3ox3bzetkpzz47y4taajbjb5h3hl/video.mkv"custommode="Stage6"wmode="transparent"width="600"height="400"previewImage="http://108.178.29.46/i/00009/kpw0suyotby3.jpg"autoPlay="false"bannerEnabled="false"previewImage=""allowContextMenu="false"previewMessage="Play"pluginspage="http://go.divx.com/plugin/download/"></embed></object>');
To get them separately it's relatively easy:

Code:
addVariable\('file','(.+?)video.+'\)
Code:
<param name="src"value="(.+?)video.+"
But I'd like to come up with a regex that can handle both scenarios.. and this is where i get stuck :)
 

Eldorado

Moderator
Staff member
May 7, 2012
990
0
16
I got something to work, but I don't like it.. maybe there's a cleaner way?

Code:
("video/divx"src="|addVariable\('file',')(.+?)video[.]
 

Bstrdsmkr

New member
Mar 16, 2012
763
0
0
You're overthinking it lol. Think about what the two have in common. They have an identifying prefix:
addVariable\('file',' and <param name="src"value="

and a closing suffix:
video.+'\) and video.+"

So the regex needs to identify those three parts. Capture either prefix:
(addVariable\('file',\s?'|<param name="src"value=")

Capture either suffix:
('\);|")

Make sure the stuff in between makes sense and avoid false positives:
(.+?)video\..{3}

Stitch them all together, then make the prefix and suffix non-capturing:
(?:addVariable\('file',\s?'|<param name="src"value=")(.+?)video\..{3}(?:'\);|")