Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to replace the characters in strings with '#'s by using regex in Python

How can I replace the contents of strings with #'s in Python? Assume no comments, no multiple lines for one string. Like if there is a line in a python file:

print 'Hello' + "her mom's shirt".

This will be translated into:

print '#####' + "###############".

It's like a filter to deal with every line in a python file.

like image 726
antonio081014 Avatar asked Feb 26 '23 05:02

antonio081014


1 Answers

If you're using Python and the thing you're parsing is Python there's no need to use regexp since there's a built-in parser.

like image 109
Matti Virkkunen Avatar answered Feb 28 '23 17:02

Matti Virkkunen