Julien wrote:
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'
the easiest way is to replace the things you don't want with an empty
string:
>>> re.sub("\W", "", "[EMAIL PROTECTED]")
'si_98udasgf'
("\W" matches everything that is "not numbers, letters, or underscores",
where the alphabet defaults to ASCII. to include non-ASCII letters, add
"(?u)" in front of the expression, and pass in a Unicode string).
</F>
--
http://mail.python.org/mailman/listinfo/python-list