Gossamer Forum
Home : General : Perl Programming :

$scores =~ s/???//sg;

Quote Reply
$scores =~ s/???//sg;
Hi there

I have html page, which I would like to extract info from.
It has baseball scores and lots of html junk between the data (and sometimes its not same html ie font size and others keep changing).
If I can figure out, how to extract just few numbers, I will be fine. Data always comes up as a:

wins^losts^ties and its always something between 0 and up to three digit number 104^78^8 or 0^8^0

How do I build the code? It should be just one line right?

Something like: $scores =~ s/(.*?.).^.(.*?.).^.(.*?.)/Wins:$1 Losts:$2 Ties:$3/sg;

How do I add a code to limit to only get the record if its up to three digit number?
Since page has sometimes has "^" mark somewhere else on the page to list something else.Crazy
Quote Reply
Re: [Suomi] $scores =~ s/???//sg; In reply to
Not definate, buit I would imagine you need to use the {1,3} type thing, i.e.;

$scores =~ m/(.*?.){1,3}.^.(.*?.){1,3}.^.(.*?.){1,3}/;
$got_scores = "Wins:$1 Looses:$2 Ties:$3";

Hope that helps :D

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] $scores =~ s/???//sg; In reply to
Do you know what .(.*?.) is doing ??

You know that ^ is a special character too right?

Something like this is far more accurate:

Code:
($win, $loss, $tie) = $scores =~ m/(\d{1,3})\^(\d{1,3})\^(\d{1,3})/s;

Last edited by:

Paul: Oct 23, 2002, 3:44 AM
Quote Reply
Re: [Paul] $scores =~ s/???//sg; In reply to
Thanks that did it Cool
Quote Reply
Re: [Paul] $scores =~ s/???//sg; In reply to
Ok how about this same sample but for digits?
I tried replacing all \d with this: [A-Za-z0-9] but no luck.
like this:
($win, $loss, $tie) =~ m/([A-Za-z0-9]{1,3})([A-Za-z0-9]{1,3})([A-Za-z0-9]{1,3})/s;

What does {1,3} do? (I assume 3 is for number of digits, but what does 1 mean?

Thanks
Quote Reply
Re: [Suomi] $scores =~ s/???//sg; In reply to
Quote:
What does {1,3} do? (I assume 3 is for number of digits, but what does 1 mean?

That means it must have at least one charachter, but no more than 3.

Afraid I'm not quite sure what you are trying to achive though? Do you have alpha charachters in these values now?

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] $scores =~ s/???//sg; In reply to
Yep something similar.

I have now few lines of text, which I need to extract.
first word is 12 characters (Alpha), second word is 8 characters(Alpha), third one has 4 chars (numbers only)

Sometimes lenght of the word changes, but it always starts at the same "spot" (second word starts at 13th character on line, third starts at 21st...)

Thanks