logo

internet.com
Join the free
WDVL newsletter!

home

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

Up to => Home / Authoring / Scripting / Tutorial

Instantly look up a "techie" word using Webopedia!!


internet.com
e-commerce
WebDeveloper Network


The leading seminar for Affiliate Marketing on the Internet.

Copyright 1999 internet.com Corporation. Legal Notices. Privacy Policy.

www.internet.com