Dear Dinesh,

if you're using the regular expression only once, I would recommend:
without_numbers = " ".join(re.split(" [0-9]+ ", phrase))

If not, compile the regular expression first and use the compiled version.

Regards,
Benoit Thiell.

On Sat, 2 Aug 2008, Noufal Ibrahim wrote:

Alan Gauld wrote:

"Dinesh B Vadhia" <[EMAIL PROTECTED]> wrote

I want to remove whole numbers from text but retain numbers
attached to words.

Is this a homework?
If so we can only offer suggestions to direction but not give solutions.

What is the best to do this using re?

Yes, use re to define a pattern then use sub() to replace with
an empty string


If you're having trouble with writing regular expressions, you can either use http://www.weitz.de/regex-coach/ (Regex-coach) or Emacs re-builder mode for some interactive training.


--
~noufal
http://nibrahim.net.in/
_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to