this is the problem: use regular expressions to prove that word "Bug" is in the 3 row from the end of table in the html tagged file:
shell> cat file1.txt <table> <tr><td>row 1</td></tr> <tr><td>row 2</td></tr> <tr><td>row 3</td></tr> <tr><td>Bug some word</td></tr> <tr><td>row 4</td></tr> <tr><td>row 5</td></tr> </table> shell> shell> cat file2.txt <table> <tr><td>row 1</td></tr> <tr><td>row 2</td></tr> <tr><td>row 3</td></tr> <tr><td>Bug some word</td></tr> <tr><td>row 4</td></tr> <tr><td>row 5</td></tr> <tr><td>row 6</td></tr> <tr><td>row 7</td></tr> </table> shell> this is my perl : #!/usr/bin/perl use warnings; use strict; my $file; while(<>){ $file.=$_; } print "matches: $1\n" if ($file =~ /<table>.+(Bug.+?)<\/td><\/tr>\s*(<tr>.+?<\/tr>\s+){2}<\/table>/s); shell> it does matches my string "Bug some word" in both file1.txt and file2.txt, should only match file1.txt frustrated! what is wrong here? thank you! On 10/13/06, I. B. <[EMAIL PROTECTED]> wrote:
thank you for reponse! unfortunately I have to use regex to solve this problem. I was trying to simplify: $file=~/<table>.+Bug.+<\/tr>\s*<tr>.+<\/tr>\s*<tr>.+?<\/tr>\s*<tr>.+?<\/tr>\s*<\/table>/; still does not work!!! > On 10/12/06, Dr.Ruud <[EMAIL PROTECTED]> wrote: > > I . B . schreef: > > > i have a task to verify that word "Bug" is in the table in the 3rd > > row from the buttom, i came up with regex , but it doesnt work. > > can anyone please take a look? > > > > #/usr/bin/perl -w > > Get rid of the "-w" and insert > > use warnings; > use strict; > > > > [...] > > > /<table>(.+Bug[^(<tr>)]+<\/tr>)\s*(<tr>.+<\/tr>\s+){2}[^(<\/tr>)]*<\/tab > > le>/s); > > You should not use a regex but a proper HTML parser. > > > Regarding your regex: > > [^(<tr>)]+ > > doesn't mean what you think it does. With the [^...], you are building a > character class that may not contain one of the characters "()<>rt". > See `perldoc perlre`. > > -- > Affijn, Ruud > > "Gewoon is een tijger." > > > -- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > <http://learn.perl.org/> <http://learn.perl.org/first-response > > > >