Regular expressions in python are slightly less handy than in perl, because
they're implemented as a module, not as a built-in.
The following should do the trick:
>>> text = "This is a \'test\'"
>>> print text
This is a 'test'
>>> import re
>>> text2 = re.sub("\'", "", text)
>>> print text2
This is a test
re is the regular expression module.
Note that regular expression patterns are input as strings, unlike perl; this
means you have to escape a lot more things. (Like that single-quote)
For the whole shebang, have a look at
<http://www.python.org/doc/2.4/lib/module-re.html>
--Mac
On Thu, Mar 24, 2005 at 04:32:52PM -0900, Adam bultman wrote:
> Anthony Valentine wrote:
>
> >Hello everyone!
> >
> >I am very new to python and cannot seem to figure out how to perform a
> >simple text substitution.
> >
> >I want to remove all single quotes from a line of text.
> >
> >In perl, I would use:
> > $var =~ s/'//g;
> >
> >Does anyone know how to do this in python?
> >
> >Thanks in advance!
> >
> >Anthony Valentine
> >
> >
> >
> >
> I don't know python, but you might try escaping that single-quote?
>
> Adam
>
>
> >---------
> >To unsubscribe, send email to <aklug-request@aklug.org>
> >with 'unsubscribe' in the message body.
> >
> >
> >
>
> ---------
> To unsubscribe, send email to <aklug-request@aklug.org>
> with 'unsubscribe' in the message body.
>
-- Julian "Mac" Mason mac@cs.hmc.edu Computer Science '06 (909)-607-3129 Harvey Mudd College -- Attached file included as plaintext by Ecartis -- -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.0 (FreeBSD) iD8DBQFCQ3xy1AphoTGXiN0RAnp0AJ9qf5oV68tMpKVJhFaegX2XqUxQlwCeNuWf 23SGQhrQo84yKE2c5iocZ5M= =NpR6 -----END PGP SIGNATURE----- --------- To unsubscribe, send email to <aklug-request@aklug.org> with 'unsubscribe' in the message body.Received on Thu Mar 24 17:50:19 2005
This archive was generated by hypermail 2.1.8 : Thu Mar 24 2005 - 17:50:19 AKST