<?xml version="1.0" encoding="windows-1252"?>
<node id="968" title="Character Class Abbreviations" created="1999-11-11 20:29:26" updated="2005-08-15 16:42:55">
<type id="956">
perltutorial</type>
<author id="113">
root</author>
<data>
<field name="doctext">
Character class abbreviations allow you to match any of a set of characters without too much hassle.
One way to do this is to put the set of characters you want to match from within [].  
For instance &amp;#091;0123456789&amp;#093; would allow you to match any of those numbers.  This can be 
kind of cumbersome. You can also negate a character class by placing a caret at the front of it.  For
instance &amp;#091;^0123456789&amp;#093; matches anything that is not a number.  You shouldn't be surprised that Perl makes your life much easier by 
defining some character class a bbreviations.  These are alphanumeric characters preceded by a 
backslash.  Perl allows you to match any number with a \d in your regular expression.&lt;BR&gt;&lt;BR&gt;

Now for a quick word about metacharacters.  Metacharacters are characters that have special meaning within regular 
expressions.  Therefore if you put them into a regular expression they won't match literally.  Unless you precede the 
metacharacter with a \.  The metacharacters are \|()$^.?* Now for a quick word about each of them do before
we return to character class abbreviations.
&lt;BR&gt;
&lt;TABLE border=1 cellpadding=2&gt;
&lt;TR&gt;&lt;TD&gt;Metacharacter(s)&lt;/TD&gt;&lt;TD&gt;Meaning&lt;/TD&gt;&lt;/TR&gt;
&lt;TR&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD&gt;Matches any character besides newline&lt;/TD&gt;&lt;/TR&gt;
&lt;TR&gt;&lt;TD&gt;()&lt;/TD&gt;&lt;TD&gt;Used for grouping characters&lt;/TD&gt;&lt;/TR&gt;
&lt;TR&gt;&lt;TD&gt;&amp;#091;&amp;#093;&lt;/TD&gt;&lt;TD&gt;Used for defining character classes&lt;/TD&gt;&lt;/TR&gt;
&lt;TR&gt;&lt;TD&gt;|&lt;/TD&gt;&lt;TD&gt;Used for or in regular expression&lt;/TD&gt;&lt;/TR&gt;
&lt;TR&gt;&lt;TD&gt;\&lt;/TD&gt;&lt;TD&gt;Denotes the beginning of a character class abbreviation, or for the following metacharacter to be matched literally&lt;/TD&gt;&lt;/TR&gt;
&lt;TR&gt;&lt;TD&gt;*&lt;/TD&gt;&lt;TD&gt;Quantifier matches 0 or more of the previous character or group of characters&lt;/TD&gt;&lt;/TR&gt;
&lt;TR&gt;&lt;TD&gt;?&lt;/TD&gt;&lt;TD&gt;Makes a quantifier nongreedy&lt;/TD&gt;&lt;/TR&gt;
&lt;TR&gt;&lt;TD&gt;^&lt;/TD&gt;&lt;TD&gt;Matches the beginning of a string (or line if /m is used)&lt;/TD&gt;&lt;/TR&gt;
&lt;TR&gt;&lt;TD&gt;$&lt;/TD&gt;&lt;TD&gt;Matches the end of a string (or line if /m is used)&lt;/TD&gt;&lt;/TR&gt;
&lt;/TABLE&gt;
&lt;BR&gt;
&lt;BR&gt;Now lets define some character classes&lt;BR&gt;&lt;BR&gt;
&lt;TABLE border=1 cellpadding=2&gt;
&lt;TR&gt;&lt;TD&gt;Character Class&lt;/Td&gt;&lt;TD&gt;Meaning&lt;/TD&gt;&lt;TR&gt;
&lt;TR&gt;&lt;TD&gt;\d&lt;/TD&gt;&lt;TD&gt;digit or &amp;#091;0123456789&amp;#093;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR&gt;&lt;TD&gt;\D&lt;/TD&gt;&lt;TD&gt;nondigit or &amp;#091;^0123456789&amp;#093;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR&gt;&lt;TD&gt;\w&lt;/TD&gt;&lt;TD&gt;word (alphanumeric) or &amp;#091;a-zA-Z_0-9&amp;#093;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR&gt;&lt;TD&gt;\W&lt;/TD&gt;&lt;TD&gt;nonword&lt;/TD&gt;&lt;/TR&gt;
&lt;TR&gt;&lt;TD&gt;\b&lt;/TD&gt;&lt;TD&gt;word boundary&lt;/TD&gt;&lt;/TR&gt;
&lt;TR&gt;&lt;TD&gt;\s&lt;/TD&gt;&lt;TD&gt;whitespace character &amp;#091 \t\r\n\f&amp;#093;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR&gt;&lt;TD&gt;\S&lt;/TD&gt;&lt;TD&gt;non whitespace character&lt;/TD&gt;&lt;/TR&gt;
&lt;/TABLE&gt;
&lt;BR&gt;
&lt;BR&gt;
That's a lot of information to get a handle on.  So lets check out [pattern-matching examples]
</field>
</data>
</node>
