Changing entities
Kent Johnson
kent37 at tds.net
Thu Jun 9 14:19:45 EDT 2005
Daniel wrote:
> I need match a regular expression, change it erasing the other strings
> after this. Just like:
>
> a = "I'm going send to out of space, find another race"
>
> And I want to match "space" instance, and erase the other.
If you mean you want to get rid of everything after 'space', this will do it:
>>> import re
>>> a = "I'm going send to out of space, find another race"
>>> re.sub('space.*', 'space', a)
"I'm going send to out of space"
You should read this and learn to make your own regexes:
http://www.amk.ca/python/howto/regex/
Kent
More information about the Python-list
mailing list