anomy-list

A few more hints on using perl regexps.

From: Bjarni R. Einarsson (29370@xyz.molar.is)
Date: Mon 07 Jan 2002 - 19:43:47 UTC

  • Next message: Dave Cridland: "Re: Announcing sanitizer.pl, revision 1.48"

    On 2002-01-07, 14:33:07 (-0500), Brett Simpson wrote:
    > What effect does the asterisk have as opposed to the first>
    > expression? Thanks.
    >
    > (?i)\.(exe)$
    >
    > and
    >
    > (?i)\.(exe)*$

    An asterisk matches zero-or-more of the preceding entity (be it a character,
    wildcard or something enclosed in parenthesis).

    So the first would match only "blah.exe", but the second would match
    "blah." and "blah.exe" (and "blah.exe.exe.exe.exe.exe").

    More hints:

     - a plus matches one or more of something.
     - the $ sign is binding the expression to the end of the word, so
       neither of the above will match "blah.exe.foo".
     - a dot (.) is generally a wildcard matching anything, which is why
       it is escaped out using a \ in the above regexps to match only the
       dot preceding the extension (the regexp ".exe$" would match the
       filename "blahexe").
     - A parenthesis can contain multiple choices, thus the expression
       "\.(exe|bat|pif)$" will match any files ending in ".exe", ".bat"
       or ".pif".

    I suggest checking out "man perlre" for a more detailed description
    of Perl's regular expression syntax, which is used almost (not
    quite) directly by the Sanitizer.

    -- 
    Bjarni R. Einarsson                           PGP: 02764305, B7A3AB89
     29370@xyz.molar.is                -><-              http://bre.klaki.net/
    

    Check out my open-source email sanitizer: http://mailtools.anomy.net/ Spammers, please send plenty of email to: 29504@xyz.molar.is



    hosted by molar.is