On Jul 17, 10: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'
>
> Would you have any hint?
>
> Thanks a lot!
>
> JulienOne quick and dirty way would be... import string safe_chars = string.ascii_letters + string.digits + '_' test_string = '[EMAIL PROTECTED]' ''.join([char if char in safe_chars else '' for char in test_string]) you could also use a translation table, see string.translate (the table it uses can be made with string.maketrans) -- http://mail.python.org/mailman/listinfo/python-list
