[FRPythoneers] Regular Expressions

J. Wayde Allen wallen at its.bldrdoc.gov
Tue Jun 4 14:53:54 MDT 2002

On Mon, 3 Jun 2002, Sean Reifschneider wrote:

>    >>> newField = re.sub(r'[a-zA-Z ]', '', field)

I've just been spending some quality time with my web browser and the
regular expression howto, to try and understand this syntax better.  Let
me see if I've got this right.

The r'[a-zA-Z ]' is a raw string, so characters such as backslashes match
themselves and don't need escaped (couldn't figure out what that r was for
for a while).  That means that this specifies a matching pattern for both
upper and lower case alphabetical characters and spaces.  This is listed
here since the string was not initially compiled.  The actual command says
to replace matches of any of these characters in the field with the null
string so that would ultimately leave us with only those characters that
don't match in the variable newfield.  Is this correct?

I'm wondering, if for cgi page with a number of fields if compiling the
match string before testing each field wouldn't be more efficient than
compiling the string individually for each test?

- Wayde
  (wallen at its.bldrdoc.gov)

More information about the FRPythoneers mailing list