Efficient string manipulation , Help please

Scott Wolford wolford at enews.nrl.navy.mil
Thu Jul 8 12:54:20 EDT 1999


If you just want to remove the ' and " characters no matter what the user
intended, then take a look at the re regular expression package. Something
like:

import re
awkstr = 'awkward""st\'ring'
quote_re = re.compile('["\']')
print awkstr
awkstr = quote_re.sub('', awkstr)
print awkstr


Sreekant Kodela wrote:

> Dear all
>
> I seem to be in trouble here. I am trying to make some cgi scripts for
> my web site. I am using the postgresql as the backend db and a form
> based address book and news forum etc. The problem is everything is
> working ok as long as noone uses ' and " in the text. If they do, bingo
> , postgres refuses to accept. I tried using string library [mainly
> string.join(string.split('awkward'"'st'ring')). It works sometimes and
> doesn't some times.
>
> Any better and efficient way to deal with this situation !
>
> Any suggestions and ideas will be greatly appreciated.
>
> Thanks
> sreekant





More information about the Python-list mailing list