[Tutor] Question on regular expressions (fwd)
Danny Yoo
dyoo at hkn.eecs.berkeley.edu
Thu May 25 02:49:09 CEST 2006
[forwarding to tutor, although it looks like Andrew's making some good
headway from other messages]
---------- Forwarded message ----------
Date: Wed, 24 May 2006 14:59:43 -0400
From: Andrew Robert <andrew.arobert at gmail.com>
To: Danny Yoo <dyoo at hkn.eecs.berkeley.edu>
Subject: Re: [Tutor] Question on regular expressions
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hey Danny,
Your code put me right on track.
- From that point, I crafted the following code.
What is confusing is how to take the captured character and transform it
into a 3 digit hex value.
Do you know how that might be accomplished?
#!/usr/bin/python
import re
# Evaluate captured character as hex
def ret_hex(ch):
return chr((ord(ch) + 1 ) % 256 )
# Evaluate the value of whatever was matched
def eval_match(match):
return ret_hex(match.group(0))
# open file
file = open(r'm:\mq\mq\scripts\sigh.txt','r')
# Read each line, pass any matches on line to function for
# line in file.readlines():
for line in file:
a=re.sub('[^\w\s]',eval_match, line)
print a
- --
Thank you,
Andrew Robert
Systems Architect
Information Technologies
MFS Investment Management
Phone: 617-954-5882
E-mail: arobert at mfs.com
Linux User Number: #201204
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.3 (MingW32)
iD8DBQFEdK0fDvn/4H0LjDwRAuipAKDFqOeQQkJ+WkaI+veIgC8oEn9/CQCfUfNO
xb7AT8W04B/F684i+Lw6kxw=
=5mPe
-----END PGP SIGNATURE-----
More information about the Tutor
mailing list