Regular Expressions :: introduction
Regular expressions are a mini-language for matching patterns in strings so that you can find, replace, and/or capture parts of strings. One way to think of this is as "math for strings." *
match operator: string =~ m/regex/
returns true if match found, false otherwise
negative match operator: string !~ m/regex/
returns true if match NOT found, false if match found
simplest use is with conditionals:
# to test if a pattern is there my $string = "has a\ttab"; if ($string =~ m/\t/) { print "has a tab\n"; } else { print "has NO tabs\n"; }
A few examples in this section have been generously provided by A. Lewin, A Lin, J. Deri, et al: Harvard Extension School :: Practical Perl.