On Jul 17, 9:13 am, Julien <[EMAIL PROTECTED]> wrote:
> Hi,
>
> I can't seem to find the right regular expression to achieve what I
> want. I'd like to remove all characters from a string that are not
> numbers, letters or underscores.
>
> For example:
>
> >>> magic_function('[EMAIL PROTECTED]')
>
> str: 'si_98udasgf'
For speed, you can use 'string.translate', but simplest is to use a
comprehension:
import string
def magic_function(s, keep=string.ascii_letters + string.digits +
'_'):
return ''.join(c for c in s if c in keep)
--
Paul Hankin
--
http://mail.python.org/mailman/listinfo/python-list