re

David C. Ullrich dullrich at sprynet.com
Wed Jun 4 12:21:36 EDT 2008


Actually using regular expressions for the first
time. Is there something that allows you to take the
union of two character sets, or append a character to
a character set?

Say I want to replace 'disc' with 'disk', but only
when 'disc' is a complete word (don't want to change
'discuss' to 'diskuss'.) The following seems almost
right:

  [^a-zA-Z])disc[^a-zA-Z]

The problem is that that doesn't match if 'disc' is at
the start or end of the string. Of course I could just
combine a few re's with |, but it seems like there should
(or might?) be a way to simply append a \A to the first
[^a-zA-Z] and a \Z to the second.

-- 
David C. Ullrich



More information about the Python-list mailing list