Regular expression problem

abranches pedrof.abranches at gmail.com
Sun Jun 22 23:13:33 CEST 2008


Hello everyone.

I'm having a problem when extracting data from HTML with regular
expressions.
This is the source code:

You are ready in the next<br /><span id="counter_jt_minutes"
style="display: inline;"><span id="counter_jt_minutes_value">12</
span>M</span> <span id="counter_jt_seconds" style="display:
inline;"><span id="counter_jt_seconds_value">48</span>S</span>

And I need to get the remaining time. Until here, isn't a problem
getting it, but if the remaining time is less than 60 seconds then the
source becomes something like this:

You are ready in the next<br /><span id="counter_jt_seconds"
style="display: inline;"><span id="counter_jt_seconds_value">36</
span>S</span>

I'm using this regular expression, but the minutes are always None...
You are ready in the next.*?(?:>(\d+)</span>M</span>)?.*?(?:>(\d+)</
span>S</span>)

If I remove the ? from the first group, then it will work, but if
there are only seconds it won't work.
I could resolve this problem in a couple of python lines, but I really
would like to solve it with regular expressions.

Thanks,
Pedro Abranches



More information about the Python-list mailing list