<?xml version="1.0" encoding="windows-1252"?>
<node id="969" title="pattern-matching examples" created="1999-11-11 21:09:39" updated="2005-08-15 16:43:25">
<type id="956">
perltutorial</type>
<author id="113">
root</author>
<data>
<field name="doctext">
&lt;code&gt;
/Lisa|Bart/  #matches either Lisa or Bart by using the | (or) operator
/Lisa\sBart/ #matches Lisa then a whitespace character and then Bart
/\w{5}/      #matches 5 alphanumeric/word characters in a row
/sub\s+\w*{/ #matches the word sub then one or more spaces and then
             #0 or more alphanumeric characters followed by a {
/\d{3}-\d{4} #matches a phone number of the form 555-1234
             #3 numbers followed by a - followed by 4 numbers
&lt;/code&gt;
A great way to test just what a given pattern matches is the
program below:
&lt;p&gt;&lt;tt&gt;
#!/usr/bin/perl&lt;br&gt;
while(&amp;lt;&amp;gt;){&lt;br&gt;
&amp;nbsp; &amp;nbsp; print if m!&lt;/tt&gt;&lt;I&gt;your pattern here&lt;/I&gt;&lt;tt&gt;!;&lt;br&gt;
}&lt;br&gt;
&lt;/tt&gt;&lt;/p&gt;
All you have to do is drop your test pattern 
into place.  Then run the program and type a line of text
in at a time.  If the pattern matches it will echo the line of text to the screen.
When you have played with it enough simply type Ctrl-C.
&lt;p&gt;
You should now take some time to learn about [split and join]
&lt;/p&gt;</field>
</data>
</node>
