RE: regexp question

From: Joe Harris (jfh6200@tx.rr.com)
Date: Sat Oct 18 2008 - 08:12:51 ART


I'm assuming your doing this using the MPF via the ASA...if you wish to
match on a file name with a particular extension ".exe" in your case you
might be inclined at first to use the expression:

regex _exe ".exe"

The anticipation is that you would match just strings with the occurrence of
".exe" but it is not so, because the "." is a special character that denotes
the any match operation. In effect the regular expression ".exe" will match
such strings as ".exe", "aexe", "bexe" and so forth, which is not the
intention here. To make sure that you only match the string ".exe" we will
have to "escape" the "." with a forward slash ("\") so the regular
expression state machine will not interpret the "." as the "any" operator
but as the literal "period" symbol. The correct way to construct the regular
expression is shown here:

regex _exe "\.exe"

This regular expression will now match any string that has an occurrence of
".exe" however if this is meant to be used as a way to match filenames with
the extension ".exe" but not only just the extension ".exe", we actually
want to match a valid filename where the name portion is at least one
character long. Here is how we do that:

regex _exe ".+\.exe"

In common terms this means match a string with at least 1 characters before
the ".exe" extension. To make this example complete with mixed case handling
the regular expression ends up as:

regex _exe ".+\.[Ee][Xx][Ee]"

The first period tells the regex to match upon any character and the '+'
after the period is known as a quantifier notation and tells the regex to
match at least one character to the left of the quantifier notation.
Quantifier notations have special meanings within regex's just as the period
does and they are used to determine how many times a given notation to the
immediate left of the quantifier notation should repeat itself. A few
quantifier notations are listed here:

* 0 or more times
+ 1 or more times
? 0 or 1 time
{n} Exactly n number of times
{n,m} n to m number of times

So given the logic and meaning of the period and the quantifier notation, we
can actually change the regex as follows to:

 regex _exe ".*\.[Ee][Xx][Ee]"

These two sites should help to clear it all up:

http://www.javaworld.com/javaworld/jw-07-2001/jw-0713-regex.html
http://java.sun.com/j2se/1.5.0/docs/api/java/util/regex/Pattern.html

Hope this helps,

Joe Harris
CCIE No. 6200 (R/S, Sec, SP)

-----Original Message-----
From: nobody@groupstudy.com [mailto:nobody@groupstudy.com] On Behalf Of Ajay
mehra
Sent: Saturday, October 18, 2008 1:35 AM
To: ccielab@groupstudy.com
Subject: regexp question

Hi Guys,

I am not good in regexp and seeing your help to understand this.

Question says:

Disallow uploads of "*.exe" via ftp

I had a look at solution guide and it says

regex EXE ".*\.[eE][xX][eE]"

If second (.) is for . in .exe then what is 1st .(dot) for?

My answer was "*\.[eE][xX][eE]"

Also if there is any referece to understand regexp please forward it to me.

Thanks,

Ajay

Blogs and organic groups at http://www.ccie.net



This archive was generated by hypermail 2.1.4 : Sat Nov 01 2008 - 15:35:21 ARST