PDA

View Full Version : optimize my reg_exp please



MrNase
Thu 30th Jun '05, 8:21pm
Hello!

I need some help with my reg_exp :(

I have the following:


preg_match('/<font face="Arial" size="2">BOTT<\/td><td align=right bgcolor=#([a-fA-F0-9]){6}><font face="Arial" size="2">(\d+)<\/td><td align=right> <font face="Arial" size="2">(\d+:\d+)<\/td><td align=right bgcolor=#([a-fA-F0-9]){6}><font face="Arial" size="2">(\d+|-)<\/td><td align=right bgcolor=#([a-fA-F0-9]){6}><font face="Arial" size="2">(\d+|-)<\/td><td align=right> <font face="Arial" size="2">(\d+:\d+)<\/td><td align=right bgcolor=#([a-fA-F0-9]){6}><font face="Arial" size="2">(.\d+|-)<\/td><\/tr>/', $string, $match);

And it matches the following quite perfect:


<font face="Arial" size="2">BOTT</td><td align=right bgcolor=#66CCFF><font face="Arial" size="2">45</td><td align=right> <font face="Arial" size="2">01:00</td><td align=right bgcolor=#66CCFF><font face="Arial" size="2">45</td><td align=right bgcolor=#3399FF><font face="Arial" size="2">26</td><td align=right> <font face="Arial" size="2">01:00</td><td align=right bgcolor=#3399FF><font face="Arial" size="2">26</td></tr>



But there's a small problem and I need to extend the reg_exp:

Sometimes, the time is not just 01:23 or 23:40, sometimes it's just -

This regexp won't work in this case: (\d+:\d+)

I tried extending it to: ((\d+:\d+)|-)
That didn't work either :(


And: Sometimes the simple numbers have a < or > just before them so that this won't work:
(\d+|-)

I extended it to: (.\d+|-)
But that didn't work :(

And those numbers can be just - too..


Please help my.. It's nearly half past 2 in the morning here and I don't get my problem solved :(


My explanation seems to be difficult to understand ;)

The short version:

I need 2 regexps...
The first:
Match 01:00 or 12:00 or 24:00 or 00:00 and -


The second:
Match 0 to 200 and - and all numbers with a < and > in front (like <40 or >100)