stripping characters with regex

Jeff Sacksteder jwsacksteder at ramprecision.com
Wed Jan 22 22:13:04 EST 2003


I need urgent assistance. I'm cleaning up text strings containing ' ,",\ and
/ characters which are giving an enormous headache.

I have a little function like this that doesn't do what I had in mind.

def clean_text(y):
	# match any number of occurrances of these four characters
	clean = re.compile('(\\|\'|\"|\/)')
	# replace them when found with nothing - effectively deleting them
	return clean.sub( '',y)

Suggestions welcome, example code cheerfully accepted!





More information about the Python-list mailing list