A great way to test just what a given pattern matches is the program below:/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
#!/usr/bin/perl
while(<>){
print if m!your pattern here!;
}
You should now take some time to learn about split and join
|
---|
Replies are listed 'Best First'. | |
---|---|
RE: pattern-matching examples
by Anonymous Monk on Mar 23, 2000 at 01:22 UTC | |
by Aighearach (Initiate) on Apr 22, 2000 at 13:53 UTC | |
Re: pattern-matching examples
by witandhumor (Pilgrim) on Mar 28, 2004 at 04:34 UTC | |
Re: pattern-matching examples
by Anonymous Monk on Aug 17, 2004 at 06:50 UTC |
Back to
Tutorials