re.match(...) fails to find a match

Kevin Cole kjcole at well.com
Wed Jun 20 15:04:25 EDT 2001


Hi.  I'm using Python 1.5.2 under Linux, and wish to find and replace several
special characters (punctuation characters).  So, I've been attempting to test
a basic match and cannot get it to return anything.

How would I match any of [/|&{}#@^~\"] (excluding the delimiting square
brackets?

Just attempting to get an ampersand working, I've tried:

   p = re.compile('[&]+')
   p = re.compile(r'[&]+')
   p = re.compile(r'[\&]+')
   p = re.compile('[\&]+')
   p = re.compile('[\\&]+')
   p = re.compile('[\\\&]+')
   p = re.compile('[\\\\&]+')

and every other combination of r'...' and '\\\...' I can think of.  I've
tried it without the square brackets, and even with an extra set of brackets. 
But

   print p.match('This string & that string')

always returns "None".



More information about the Python-list mailing list