regex's

Andrew Cooke andrew at andrewcooke.free-online.co.uk
Mon May 15 07:22:32 EDT 2000


Insert an extra two backslashes before the three you already have.  The
string within [] is \'" and it's being parsed as an escaped single quote
and a double quote.

Also, check out the r'' syntax.

Andrew


In article <391f606a.176428420 at news1.on.sympatico.ca>,
  chibaA at TinterlogD.Tcom wrote:
> Hi,
>
> For some reason, this segment of code doesn't do what it's supposed to
> do...  (it's supposed to take any \ " 's from inputString, and return
> the same chacter preceeded with a \ to outputString).  It works great
> for the ' and " characters, but it just won't do the \.  Any idea why?
>
> def norm2mysqlinsert(inputString): # Used for insert and update in
> MySQL
>         outputString = ''
>         p=re.compile('^[\\\'\"]$')
>
>         count = 0
>         for i in inputString:
>                 if p.match(inputString[count]):
>                         outputString = outputString + "\\" +
> inputString[count]
>                 else:
>                         outputString = outputString +
> inputString[count]
>                 count = count + 1
>
>         return outputString
>


Sent via Deja.com http://www.deja.com/
Before you buy.



More information about the Python-list mailing list