How to write this regular expression?
Heiko Wundram
heiko.wundram at ceosg.de
Wed May 4 05:56:36 EDT 2005
On Wednesday 04 May 2005 11:34, could ildg wrote:
> Does it matter whether it is a homework?
Yes, it does matter. We're not your CS-class homework monkeys... :-) We're a
forum of Python programmers who aid each other at thinking about solutions,
we don't present solutions (normally), for a beautiful example of this, see
the thread about finding similarities between two wave files...
But, anyway, as an additional hint: the stuff you need to do _can_ be solved
by an RE (the language you're matching is actually regular if you impose
several restrictions), but I'd rather not do it that way. Programming a small
function which splits the string and then does the appropriate checks (by
using int) should be much easier and faster.
And in case you really need an RE, watch this monster (to match a single term
having numerical value >= 40)...
0*(([1-9][0-9]{2,})|([4-9][0-9]))
Matching numbers >= 31 isn't hard too, I leave this as an exercise to the
reader... :-) But beware, I'd guess this regex performs rather poorly with
respect to backtracking on erraneous input such as
"00000000000000000000000030"...
--- Heiko.
More information about the Python-list
mailing list