I simply want to remark out all non-word characters read from a line.

Line:
Q*bert says "#...@!$%  "

in Perl
#match each non-word character, add "\" before it, globally.

$_=s/(\W)/\\$1/g;

output:
Q\*bert\ says\ \"\...@\!\$\%\ \ \"  #perfect!  

Is there something simple like this in python?

I would imagine:
foo='Q*bert says "#...@!$%  "'
pNw=re.compile('(\W)')
re.sub(pNw,'\\'+(match of each non-word character),foo)

How do I get the match into this function?  Is there a different way to do this?


      
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to