gnumed-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Gnumed-devel] help with trimming $


From: Horst Herb
Subject: Re: [Gnumed-devel] help with trimming $
Date: Tue, 1 Mar 2005 14:38:57 +1100
User-agent: KMail/1.7.1

On Tue, 1 Mar 2005 14:05, Richard Terry wrote:
> eg 10/12/2004 Hypertension to return just Hypertension
> or 10/2000 Appendix
> 0r 2001 Cancer Bowel to return Cancer of the bowel
>
> Anyone volunteer the python code to use.

For this I wouldn't even use regular expressions (which cost a lot of 
processor time and memory)
- all examples stated start with a number, so would just parse:
if (line starts with number):
1.) read character until character not in [0-9, '.', '/', '-'] and append to 
parsestr
2.) try split parsestr with date separators ('.', '/', '-')
3.) if only one split str and length ==4: this is the date (check plausibility 
of date)
4.) else, if two split strings: assume first junk is months, last is year, 
check for plausibility
5.) else, ...

hey, it's quick and easy to do in Python, and since you are learning Python 
just now, ... a good exercise in string manipulation / parsing?

Horst




reply via email to

[Prev in Thread] Current Thread [Next in Thread]