<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>
<channel>
	<title>beer planet &#187; regexp</title>
	<atom:link href="http://beerpla.net/tag/regexp/feed/" rel="self" type="application/rss+xml" />
	<link>http://beerpla.net</link>
	<description>where things have nothing to do with beer - tutorials, tips, how-tos, thoughts, hacks, and other techy nonsense</description>
	<lastBuildDate>Sun, 08 Aug 2010 23:59:10 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
	<atom:link rel='hub' href='http://beerpla.net/?pushpress=hub'/>
		<item>
		<title>Quick Perl Snippet: Finding If A File Has A Media Extension Using Regex</title>
		<link>http://beerpla.net/2008/03/21/quick-snippet-finding-if-a-file-has-a-media-extension-using-regex/</link>
		<comments>http://beerpla.net/2008/03/21/quick-snippet-finding-if-a-file-has-a-media-extension-using-regex/#comments</comments>
		<pubDate>Fri, 21 Mar 2008 21:11:34 +0000</pubDate>
		<dc:creator>Artem Russakovskii</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[extension]]></category>
		<category><![CDATA[file]]></category>
		<category><![CDATA[media]]></category>
		<category><![CDATA[Perl]]></category>
		<category><![CDATA[regex]]></category>
		<category><![CDATA[regexp]]></category>
		<category><![CDATA[type]]></category>
		<category><![CDATA[url]]></category>
		<guid isPermaLink="false">http://beerpla.net/2008/03/21/quick-snippet-finding-if-a-file-has-a-media-extension-using-regex/</guid>
		<description><![CDATA[<p>Sometimes in my line of work, I need to figure out if a url or filename point to a media file by checking for the file extension. If it&#039;s a url, however, it may be followed by various parameters. Not to overcomplicate things, I came up with the following Perl code:</p>
<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code"><pre>#!/usr/bin/perl -w
use strict;
my $name = &#34;some_file.flv&#34;; # or http://example.com/file.mp4?foo=bar
my $is_media_type = ($name =~ /\.(wmv&#124;avi&#124;flv&#124;mov&#124;mkv&#124;mp..?&#124;swf&#124;ra.?&#124;rm&#124;as.&#124;m4[av]&#124;smi.?)\b/i);
if($is_media_type){
  print &#34;media extension found\n&#34;;
}
else{
  print &#34;not a media file\n&#34;;
}</pre></td></tr></table></div>
<p>This gets the job done without triggering any...<div class=clear></div> <a href="http://beerpla.net/2008/03/21/quick-snippet-finding-if-a-file-has-a-media-extension-using-regex/" class="read_more"><div class=excerpt-end>Read the rest of this article &#187;</div></a></p>]]></description>
			<content:encoded><![CDATA[<p>Sometimes in my line of work, I need to figure out if a url or filename point to a media file by checking for the file extension. If it&#039;s a url, however, it may be followed by various parameters. Not to overcomplicate things, I came up with the following Perl code:</p>
<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code"><pre>#!/usr/bin/perl -w
use strict;
my $name = &quot;some_file.flv&quot;; # or http://example.com/file.mp4?foo=bar
my $is_media_type = ($name =~ /\.(wmv|avi|flv|mov|mkv|mp..?|swf|ra.?|rm|as.|m4[av]|smi.?)\b/i);
if($is_media_type){
  print &quot;media extension found\n&quot;;
}
else{
  print &quot;not a media file\n&quot;;
}</pre></td></tr></table></div>
<p>This gets the job done without triggering any false positives (at least for the files/urls I&#039;ve been dealing with so far). Am I missing any obvious types? Do you have a better way to accomplish the same thing? If so, please share in the comments.</p>
<div class="shr-bookmarks shr-bookmarks-expand">
<ul class="socials">
		<li class="shr-twitter">
			<a href="http://twitter.com/home?status=Quick+Perl+Snippet%3A+Finding+If+A+File+Has+A+Media+Extension+Using+Regex+-+http://bit.ly/cMBVAD&amp;source=shareaholic" rel="nofollow" class="external" title="Tweet This!">Tweet This!</a>
		</li>
		<li class="shr-facebook">
			<a href="http://www.facebook.com/share.php?v=4&amp;src=bm&amp;u=http://beerpla.net/2008/03/21/quick-snippet-finding-if-a-file-has-a-media-extension-using-regex/&amp;t=Quick+Perl+Snippet%3A+Finding+If+A+File+Has+A+Media+Extension+Using+Regex" rel="nofollow" class="external" title="Share this on Facebook">Share this on Facebook</a>
		</li>
		<li class="shr-googlebuzz">
			<a href="http://www.google.com/buzz/post?url=http://beerpla.net/2008/03/21/quick-snippet-finding-if-a-file-has-a-media-extension-using-regex/&amp;imageurl=" rel="nofollow" class="external" title="Post on Google Buzz">Post on Google Buzz</a>
		</li>
		<li class="shr-hackernews">
			<a href="http://news.ycombinator.com/submitlink?u=http://beerpla.net/2008/03/21/quick-snippet-finding-if-a-file-has-a-media-extension-using-regex/&amp;t=Quick+Perl+Snippet%3A+Finding+If+A+File+Has+A+Media+Extension+Using+Regex" rel="nofollow" class="external" title="Submit this to Hacker News">Submit this to Hacker News</a>
		</li>
		<li class="shr-reddit">
			<a href="http://reddit.com/submit?url=http://beerpla.net/2008/03/21/quick-snippet-finding-if-a-file-has-a-media-extension-using-regex/&amp;title=Quick+Perl+Snippet%3A+Finding+If+A+File+Has+A+Media+Extension+Using+Regex" rel="nofollow" class="external" title="Share this on Reddit">Share this on Reddit</a>
		</li>
		<li class="shr-digg">
			<a href="http://digg.com/submit?phase=2&amp;url=http://beerpla.net/2008/03/21/quick-snippet-finding-if-a-file-has-a-media-extension-using-regex/&amp;title=Quick+Perl+Snippet%3A+Finding+If+A+File+Has+A+Media+Extension+Using+Regex" rel="nofollow" class="external" title="Digg this!">Digg this!</a>
		</li>
		<li class="shr-delicious">
			<a href="http://delicious.com/post?url=http://beerpla.net/2008/03/21/quick-snippet-finding-if-a-file-has-a-media-extension-using-regex/&amp;title=Quick+Perl+Snippet%3A+Finding+If+A+File+Has+A+Media+Extension+Using+Regex" rel="nofollow" class="external" title="Share this on del.icio.us">Share this on del.icio.us</a>
		</li>
		<li class="shr-stumbleupon">
			<a href="http://www.stumbleupon.com/submit?url=http://beerpla.net/2008/03/21/quick-snippet-finding-if-a-file-has-a-media-extension-using-regex/&amp;title=Quick+Perl+Snippet%3A+Finding+If+A+File+Has+A+Media+Extension+Using+Regex" rel="nofollow" class="external" title="Stumble upon something good? Share it on StumbleUpon">Stumble upon something good? Share it on StumbleUpon</a>
		</li>
		<li class="shr-mail">
			<a href="mailto:?subject=%22Quick%20Perl%20Snippet%3A%20Finding%20If%20A%20File%20Has%20A%20Media%20Extension%20Using%20Regex%22&amp;body=Link: http://beerpla.net/2008/03/21/quick-snippet-finding-if-a-file-has-a-media-extension-using-regex/ (sent via shareaholic)%0D%0A%0D%0A----%0D%0A Sometimes%20in%20my%20line%20of%20work%2C%20I%20need%20to%20figure%20out%20if%20a%20url%20or%20filename%20point%20to%20a%20media%20file%20by%20checking%20for%20the%20file%20extension.%20If%20it%27s%20a%20url%2C%20however%2C%20it%20may%20be%20followed%20by%20various%20parameters.%20Not%20to%20overcomplicate%20things%2C%20I%20came%20up%20with%20the%20following%20Perl%20code%3A%0A%0A%23%21%2Fusr%2Fbin%2Fperl%20-w%0Ause%20strict%3B%0Amy" rel="nofollow" class="external" title="Email this to a friend?">Email this to a friend?</a>
		</li>
</ul>
<div style="clear:both;"></div>
</div>
Similar Posts:<ul><li><a href="http://beerpla.net/2009/04/08/perl-finding-files-the-fun-and-elegant-way/" rel="bookmark" title="April 8, 2009">[Perl] Finding Files, The Fun And Elegant Way</a></li>
<li><a href="http://beerpla.net/2007/08/04/watch-a-useful-linux-command-you-may-have-never-heard-of/" rel="bookmark" title="August 4, 2007">Watch &#8211; A Useful Linux Command You May Have Never Heard Of</a></li>
<li><a href="http://beerpla.net/2009/03/17/twitter-autocomplete-auto-url-expansion-auto-url-shortener-auto-pagination-rt-button-nested-replies-inline-media-embed-search-tabs-and-more/" rel="bookmark" title="March 17, 2009">Twitter.com Autocomplete, Auto URL Expansion, Auto URL Shortener, RT Button, Nested Replies, Inline Media Embed, Search Tabs, And More</a></li>
<li><a href="http://beerpla.net/2008/04/26/how-to-list-files-within-tgz-targz-archives/" rel="bookmark" title="April 26, 2008">How To List Files Within tgz (tar.gz) Archives</a></li>
<li><a href="http://beerpla.net/2010/01/13/wordpress-plugin-development-how-to-include-css-and-javascript-conditionally-and-only-when-needed-by-the-posts/" rel="bookmark" title="January 13, 2010">[WordPress Plugin Development] How To Include CSS and JavaScript Conditionally And Only When Needed By The Posts</a></li>
</ul><!-- Similar Posts took 12.603 ms --><p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://beerpla.net/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://beerpla.net/2008/03/21/quick-snippet-finding-if-a-file-has-a-media-extension-using-regex/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
