![](/WDVL/Website/Design/images/spacer.gif) |
Pattern matching with "//"
Pattern matching with "//"
- Perl invokes a
powerful tool for pattern matching that
gives the program great flexibility in controlling matches.
In Perl, a string is matched by placing it between two
slashes as follows:
/[pattern_to_match]/
- Thus, /eric/ matches for the string "eric". You may also
match according to whole classes of characters using the
square brackets ([]). The pattern match will then match
against any of the characters in the class. For example, to
match for any single even numbered digit, you could use
the following match:
/[02468]/
- For classes including an entire range of characters, you
may use the dash (-) to represent the list. Thus, the
following matches any single lower case letter in the
alphabet:
/[a-z]/
- Likewise, you may use the caret (^) character within the
square brackets to match every character that is "not"
in the class. The following matches any single character
that is not a digit.
/[^0-9]/
Additional Resources:
Regular Expressions
Table of Contents
Matching Operators
| ![](/WDVL/Website/Design/images/spacer.gif) |
|