<?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>Blog::Quibb &#187; regular expressions</title> <atom:link href="http://blog.quibb.org/tag/regular-expressions/feed/" rel="self" type="application/rss+xml" /><link>http://blog.quibb.org</link> <description>Software development and more.</description> <lastBuildDate>Mon, 21 Nov 2011 05:12:26 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.3.1</generator> <item><title>Regular Expressions Review</title><link>http://blog.quibb.org/2009/02/regular-expressions-review/</link> <comments>http://blog.quibb.org/2009/02/regular-expressions-review/#comments</comments> <pubDate>Sat, 14 Feb 2009 18:18:47 +0000</pubDate> <dc:creator>Joe</dc:creator> <category><![CDATA[Java]]></category> <category><![CDATA[Python]]></category> <category><![CDATA[Ruby]]></category> <category><![CDATA[regular expressions]]></category><guid isPermaLink="false">http://blog.quibb.org/?p=25</guid> <description><![CDATA[A hobby of mine is to learn new programming languages.  I try and learn at least one a year, and use it for more than just a hello world app.  So this year is the year of python, where if I&#8217;m required to write a script Python is the go to guy.  Having that said, [...]]]></description> <content:encoded><![CDATA[<p>A hobby of mine is to learn new programming languages.  I try and learn at least one a year, and use it for more than just a hello world app.  So this year is the year of python, where if I&#8217;m required to write a script Python is the go to guy.  Having that said, I recently had a need for regular expressions, so python was used.</p><p>Being most familiar with Java and Ruby, Python seems a little in between, but one feature that stuck out was the regular expression syntax.  Python let&#8217;s you put a &#8216;r&#8217; in front of the quote to denote raw input.  This means you don&#8217;t have to escape back slashes twice (ala Java).</p><p>For those not familiar with regular expressions, here is an example of a regular expression in a few languages:</p><pre style="padding-left: 30px;">Java:
Find Slashes: "[\\\\/]"

Python:
Find Slashes: r"[\\/]"

Ruby:
Find Slashes: /[\\\/]/</pre><p>This is just a simple example to illustrate a point, but look at Java.  Find slashes has 4 backslashes.  Even if regular expressions were typically this simple (they&#8217;re not), that seems unnecessary.  Anytime it&#8217;s necessary for a backslash to make it to the regular expression processor, there much be two in the regular expression.  Another quick example, to find a period (.) the regular expression would be &#8220;\\.&#8221;.  This compounds very quickly, and makes it painful to use regular expressions in Java.</p><p>I can&#8217;t understand why Java wouldn&#8217;t adopt the python syntax of putting a &#8216;r&#8217; in from of a string to denote raw input.  At quick glance, it doesn&#8217;t seem as though it would break any currently in use regular expressions because the old syntax would continue working as expected.  It&#8217;d make them better for the future.</p><p>Here are some Regular Expression resources that I find useful:</p><p><a title="http://www.rubular.com/" href="http://www.rubular.com/">http://www.rubular.com/</a> A Ruby Regular Expression Tester</p><p><a title="http://www.fileformat.info/tool/regex.htm" href="http://www.fileformat.info/tool/regex.htm">http://www.fileformat.info/tool/regex.htm</a> A Java Regular Expression Tester</p> ]]></content:encoded> <wfw:commentRss>http://blog.quibb.org/2009/02/regular-expressions-review/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> </channel> </rss>
<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk
Page Caching using disk (enhanced)
Database Caching 4/6 queries in 0.003 seconds using disk
Object Caching 302/302 objects using disk

Served from: blog.quibb.org @ 2012-02-05 12:20:08 -->
