Patrick Talmadge
Regex Vimeo Parser
Today’s Regex is used to parse a string for Vimeo links and extract the Video_ID. Once we have the Video_ID we’re able to create a standard embed code from Vimeo links.
Supported Links:
The following Regex supports these Vimeo links and embed code snippets.
Normal URL: http://vimeo.com/9669721
Group URL: http://vimeo.com/groups/tvc/videos/32626014
New Embed: <iframe src="http://player.vimeo.com/video/9669721?title=0
&byline=0&portrait=0&color=ffffff" width="400"
height="225" frameborder="0" webkitAllowFullScreen
mozallowfullscreen allowFullScreen > </iframe >
**** Doesn't handle Vimeo's old embed code ****
Again, I’ve broken it up the Regex and commented each line.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | $regexstr = '~ # Match Vimeo link and embed code (?:<iframe [^>]*src=")? # If iframe match up to first quote of src (?: # Group vimeo url https?:\/\/ # Either http or https (?:[\w]+\.)* # Optional subdomains vimeo\.com # Match vimeo.com (?:[\/\w]*\/videos?)? # Optional video sub directory this handles groups links also \/ # Slash before Id ([0-9]+) # $1: VIDEO_ID is numeric [^\s]* # Not a space ) # End group "? # Match end quote if part of src (?:[^>]*></iframe>)? # Match the end of the iframe (?:<p>.*</p>)? # Match any title information stuff ~ix'; |
Usage Example:
This example function takes an input string and uses the above Regex to parse off the Vimeo Video_ID ($1) and add it to $iframestr to create a standard embed code.
1 2 3 4 5 6 | function ParsePostVimeo($string){ $regexstr = <<REGEX FROM ABOVE>>; $iframestr = ' <p><iframe src="http://player.vimeo.com/video/$1?title=0&byline=0&portrait=0" width="500" height="284" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe></iframe></p> '; return preg_replace($regexstr, $iframestr, $string); } |
For more Regex see Regex YouTube Parser
One Response to Regex Vimeo Parser
Leave a Reply Cancel reply
My Twitter
- Hanging out at a lake cabin with friends for the day. 21 hours ago
- P.S.A just because your riding a bike doesn't mean you need skin tight short and shirt. Your not racing right now. 2012/05/19
- @smarkowitz Thanks for following. 2012/05/19
- RT @phpfog: Because you asked for it.... PHP Fog now has cron support. http://t.co/sEZMDkAv Nice... Keep up the good work! 2012/05/18
- Does anyone else find it #ironic that Facebook is buy a company called Karma? http://t.co/Gjdi8Zds 2012/05/18
- Any glimmer of hope you had about your Facebook information being private died today. Facebook is now legal obligated maximize profits. 2012/05/18
- RT @CoffeeScript: Kicksend rewrote their entire web app in one month with a faster, leaner code base featuring CoffeeScript and Backbone ... 2012/05/18
- Glad to see normal investors not getting screwed by driving up $FB prices. It's already overvalued let it stabilize. 2012/05/18
- Spec changes mid sprint are always fun. 2012/05/17
- RT @newsycombinator: CSS-Only Clickjacking http://t.co/HI1Clhlo 2012/05/16
Archives
- December 2011
- October 2011
- August 2011
- June 2011
- April 2011
- March 2011
- February 2011
- December 2010
- November 2010
- October 2010
- August 2010
- June 2010
- May 2010
- April 2010
- March 2010
- February 2010
- January 2010
- December 2009
- November 2009
- October 2009
- September 2009
- August 2009
- July 2009
- June 2009
- May 2009
- April 2009
- March 2009
- February 2009
- January 2009
- December 2008
- November 2008
- September 2007
- July 2007
- June 2007
- April 2007
- March 2007
- February 2007
- January 2007
- December 2006
- November 2006







[...] Regex Vimeo Parser [...]