[SOLVED] Regex help
Moderator: General Moderators
[SOLVED] Regex help
Hi there,
http://uk.finance.yahoo.com/q?d=v1&p=&q=q&s=DNX&m=L
I'm currently setting up my own 'money management' system so I know exactly what my financial situation is at any one time. The above URL points to a share information page on Yahoo!. The 'mid price' of a share is given on the Last Trade: XXX p cell.
Can anyone tell me a regex that will extract the midprice, XXX. I would be really grateful!
Many thanks
Mark
http://uk.finance.yahoo.com/q?d=v1&p=&q=q&s=DNX&m=L
I'm currently setting up my own 'money management' system so I know exactly what my financial situation is at any one time. The above URL points to a share information page on Yahoo!. The 'mid price' of a share is given on the Last Trade: XXX p cell.
Can anyone tell me a regex that will extract the midprice, XXX. I would be really grateful!
Many thanks
Mark
Feyd,
I've read through some literature. I've done so in the past, but have found it very difficult to retain and also put it all together into the working whole.
Could you tell me what you think the regex should be for above and explain it? I work far better from example than from reading individual explanations of terms.
Many thanks
Mark
I've read through some literature. I've done so in the past, but have found it very difficult to retain and also put it all together into the working whole.
Could you tell me what you think the regex should be for above and explain it? I work far better from example than from reading individual explanations of terms.
Many thanks
Mark
if i get it right you want to match
it's sunday, so you have time for some homework :p
now it's up to you to throw this in a RE. I'm pretty you will find some helpful tools that will show you instantly what you are matching etc... Makes finding the wanted RE painless...<tr><td class="yfnc_tablehead1" width="48%">Last Trade:</td><td class="yfnc_tabledata1"><big><b>562.00 p</b></big></td></tr>
it's sunday, so you have time for some homework :p
So it would be something like
Is that about right?
Many thanks
Mark
Code: Select all
#<tr><td class="yfnc_tablehead1" width="48\%">Last Trade:</td><td class="yfnc_tabledata1"><big><b>*[0-9].[0-9][0-9] p</b></big></td></tr>Many thanks
Mark
probably want *? to avoid greedy matching...mjseaden wrote:So it would be something like
Code: Select all
#<tr><td class="yfnc_tablehead1" width="48\%">Last Trade:</td><td class="yfnc_tabledata1"><big><b>*[0-9].[0-9][0-9] p</b></big></td></tr>
and then use (*?[0-9].[0-9][0-9]) so you get the actual number that is matched...
people have written books on regex.mjseaden wrote:Feyd,
I've read through some literature. I've done so in the past, but have found it very difficult to retain and also put it all together into the working whole.
Could you tell me what you think the regex should be for above and explain it? I work far better from example than from reading individual explanations of terms.
Many thanks
Mark
it's complicated, most hate it, it changes in every language.
however, php supports perl regex
the orielly learning perl has 3 chapters on regex.
it's also presented in a way that makes it rather easy to understand and pick up (or so i felt when i went and used that to learn perl and finally got regesx, something 4 different teachers in college seem to have no clue how to teach)
Hi,
I'm using the following regex
And getting the following response:
Is there an obvious cause to this error, which I don't understand?
Many thanks
Mark
I'm using the following regex
Code: Select all
$price = preg_match( '#<tr><td class="yfnc_tablehead1" width="48\%">Last Trade:</td><td class="yfnc_tabledata1"><big><b>(*?[0-9].[0-9][0-9]) p</b></big></td></tr>#', $content );Code: Select all
Warning: Compilation failed: nothing to repeat at offset 98 in /home/spanishpp/public_html/personal/money.php on line 253Many thanks
Mark
Code: Select all
(*?ї0-9].ї0-9]ї0-9])- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
OK I think we've given him enough of a bruising now... some people really just can't get their head around regex.
OK here it is BUT... please go away, break this down with some regex material to refer to and undersatnd how it works. These guys are right, it gets to a point where you'll have to learn from what's being shown to you.
OK here it is BUT... please go away, break this down with some regex material to refer to and undersatnd how it works. These guys are right, it gets to a point where you'll have to learn from what's being shown to you.
<tr><td class="yfnc_tablehead1" width="48%">Last Trade:</td><td class="yfnc_tabledata1"><big><b>562.00 p</b></big></td></tr>
Code: Select all
#<tr><td class="e;yfnc_tablehead1"e; width="e;48\%"e;>Last Trade:</td><td class="e;yfnc_tabledata1"e;><big><b>(\d+\.\d{2}) p</b></big></td></tr>#sHi
The following code
Gives a result of zero - it isn't detecting the value properly. I can't see anything wrong with the PHP code, so I am assuming that the regex still doesn't work.
Mark
The following code
Code: Select all
$yahoourl = 'http://uk.finance.yahoo.com/q?d=&s=DNX&m=L';
$fp = fopen( $yahoourl, 'r' );
$content = fread($fp, 30000);
preg_match( '#<tr><td class="yfnc_tablehead1" width="48\%">Last Trade:</td><td class="yfnc_tabledata1"><big><b>(\d+\.\d{2}) p</b></big></td></tr>#', $content, $matches );
fclose($fp);
echo '£ '.number_format($matches[0],2,'.',',');Mark