<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/css" href="/stylesheets/rss.css"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  <channel>
    <title>loopkid: predefined character classes in grep</title>
    <link>http://loopkid.net/articles/2008/07/06/predefined-character-classes-in-grep</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description>sad songs make me happy</description>
    <item>
      <title>predefined character classes in grep</title>
      <description>&lt;blockquote&gt;
    &lt;p&gt;Many regex implementations have &amp;#8220;macros&amp;#8221; for various character classes. In Perl, for example, \d matches any digit ([0-9]) and \w matches any &amp;#8220;word character&amp;#8221; ([a-zA-Z0-9_]). Grep uses a slightly different notation for the same thing: [:digit:] for digits and [:alnum:] for alphanumeric characters. (&lt;a href="http://www.bsd.org/regexintro.html"&gt;BSD&lt;/a&gt;)&lt;/p&gt;
    
    &lt;p&gt;Finally,  certain  named classes of characters are predefined within bracket expressions, as follows. Their names are self explanatory, and they are [:alnum:], [:alpha:], [:cntrl:], [:digit:], [:graph:], [:lower:], [:print:], [:punct:], [:space:], [:upper:], and [:xdigit:].  For example, [[:alnum:]] means [0-9A-Za-z]. (&lt;a href="http://unixhelp.ed.ac.uk/CGI/man-cgi?grep"&gt;grep man page&lt;/a&gt;)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Was unter Ruby&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;line = "length 1450"
puts line if line =~ /\d{4}/
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;heißt wird also unter der bash mit grep zu&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;export line="length 1450"
echo $line | egrep [[:digit:]]{4}
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;was zwar die regulären Ausdrücke unnötig aufbläht, aber immerhin die gleiche Funktionalität zur Verfügung stellt.&lt;/p&gt;</description>
      <pubDate>Sun, 06 Jul 2008 15:54:00 +0200</pubDate>
      <guid isPermaLink="false">urn:uuid:b2ca6c21-592f-47f8-a7b7-d788580bd74f</guid>
      <author>Stefan</author>
      <link>http://loopkid.net/articles/2008/07/06/predefined-character-classes-in-grep</link>
      <category>Mac OS X</category>
      <category>Linux</category>
      <category>Ruby</category>
      <trackback:ping>http://loopkid.net/articles/trackback/8551</trackback:ping>
    </item>
  </channel>
</rss>
