Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Regexp help? 1

Status
Not open for further replies.

SCelia

Programmer
Feb 27, 2002
82
0
0
CA
This has got me baffled, I'm trying to match this:

<TH>Jets
<TD>9<TD>$170<TD>703328<TD>
320

And the regexp I'm using to do it is...

/\<TH\>Jets\n\<TD\>\d+\<TD\>\$(\d+)\<TD\>(\d+)\<TD\>\n(\d+)/i


the above regexp is all on one line btw.

Maybe I'm jsut too tired to spot the error, but I've been through it a dozen times and I'm sure it's correct. Hopefully you guys spot it. Celia
 
Celia,

this code, copied from your post:

$str = '<TH>Jets
<TD>9<TD>$170<TD>703328<TD>
320';

# And the regexp I'm using to do it is...

if($str =~ /\<TH\>Jets\n\<TD\>\d+\<TD\>\$(\d+)\<TD\>(\d+)\<TD\>\n(\d+)/i){
print &quot;matched\n&quot;;
} else {
print &quot;not matched\n&quot;;
}

displays 'matched' on my system (W2k, Perl 5.6.1)

Why do you think it's wrong? Mike
&quot;Experience is the comb that Nature gives us after we are bald.&quot;

Is that a haiku?
I never could get the hang
of writing those things.
 
Variables $1, $2, and $3 didn't capture anything. Celia
 
Okay it prints matched on my system too. I should point out tho that the string I'm trying to match looks like

<TH>Jets
<TD>9<TD>$170<TD>703328<TD>
320

In notepad, but it is part of the source code of an html page retrieved using LWP:UserAgent. There must be something else on the ends of the lines besides \n? It's not a space but perhaps some other funny character? Celia
 
Thanks gerry! \r\n worked instead of just \n. I would give you a helpful star but there was an error when I tried :( Thanks anyway. Celia
 
Please advise what [tt]\r[/tt] stands for??
 
Well windows uses both \r\n unix uses \n and mac uses \r.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top