introduction to web programming 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:


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:


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:


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.


Previous | Next | Table of Contents