/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
A great way to test just what a given pattern matches is the
program below:
#!/usr/bin/perl
while(<>){
print if m!your pattern here!;
}
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.
You should now take some time to learn about split and join
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|