regular expressions an text string

Peter Otten __peter__ at web.de
Thu Apr 17 09:27:58 CEST 2008


ragia wrote:

> i have to match text string char by char to a regular expressions  tht
> just allow digits 0-9 if other thing a ppear it shall be replaced with
> space.how can i do that any help?

>>> import re
>>> s = "abc123_45!6$"
>>> re.sub(r"\D", " ", s)
'   123 45 6 '

Peter



More information about the Python-list mailing list