Re: nice regular expression

2006-10-14 Thread Randal L. Schwartz
 I == I B [EMAIL PROTECTED] writes:

I unfortunately I have to use regex to solve this problem.

Why?  Is this homework?  Or is this a Java question in disguise?
Either of those are rude, having conned people into helping you
for false pretenses.

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
merlyn@stonehenge.com URL:http://www.stonehenge.com/merlyn/
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: nice regular expression

2006-10-14 Thread I . B .

1. one of the purposes of scripting languages is creating prototype.
2. as i explained before my job is to create this perl regular expression.
Which will be used in xml file.
I dont care about clients apps, they can be written on any language. I use
perl.
3. also i greatly appreciate help of this community, I found solution using
help of my former colleague
and I posted it here for others interested individuals to see. It is all
about exercising skills. And having fun.
;)




On 14 Oct 2006 10:13:16 -0700, Randal L. Schwartz merlyn@stonehenge.com
wrote:


 I == I B [EMAIL PROTECTED] writes:

I unfortunately I have to use regex to solve this problem.

Why?  Is this homework?  Or is this a Java question in disguise?
Either of those are rude, having conned people into helping you
for false pretenses.

--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777
0095
merlyn@stonehenge.com URL:http://www.stonehenge.com/merlyn/
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl
training!

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response





Re: nice regular expression

2006-10-13 Thread I . B .

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





Re: nice regular expression

2006-10-13 Thread I . B .

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
 trtdrow 1/td/tr
 trtdrow 2/td/tr
 trtdrow 3/td/tr
 trtdBug some word/td/tr
 trtdrow 4/td/tr
 trtdrow 5/td/tr
/table

shell


shell cat file2.txt

table
 trtdrow 1/td/tr
 trtdrow 2/td/tr
 trtdrow 3/td/tr
 trtdBug some word/td/tr
 trtdrow 4/td/tr
 trtdrow 5/td/tr
 trtdrow 6/td/tr
 trtdrow 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 






RE: nice regular expression

2006-10-13 Thread Charles K. Clarkson
I.B. wrote:

: unfortunately I have to use regex to solve this problem.

Why do you have to use a regex?



Charles K. Clarkson
-- 
Mobile Homes Specialist
Free Market Advocate
Web Programmer

254 968-8328

Don't tread on my bandwidth. Trim your posts.


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: nice regular expression

2006-10-13 Thread Mumia W.

On 10/13/2006 12:14 PM, I.B. wrote:

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
[...]


Don't use regular expressions to parse HTML. Use an HTML parsing module 
to parse HTML.


Now to answer your next questions:

Where can I find an HTML parsing module?
http://search.cpan.org/

Why is parsing with HTML::Parser so complicated?
It's because HTML is very complicated.




--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: nice regular expression

2006-10-13 Thread Paul Johnson
On Fri, Oct 13, 2006 at 12:36:33PM -0500, Charles K. Clarkson wrote:

 I.B. wrote:
 
 : unfortunately I have to use regex to solve this problem.
 
 Why do you have to use a regex?

Because that is what the question stipulates.

-- 
Paul Johnson - [EMAIL PROTECTED]
http://www.pjcj.net

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: nice regular expression

2006-10-13 Thread I . B .

got it! very nice, not complicated at all. I didn't know about lookahead
feature. very useful.

this file that should be matched:
TABLE
 TRTDrow 1/TD/TR
 TRTDrow 2/TD/TR
 TRTDrow 3/TD/TR
 TRTDBug some word/TD/TR
 TRTDrow 4/TD/TR
 TRTDrow 5/TD/TR
/TABLE

this is file that should not be matched:
TABLE
 TRTDrow 1/TD/TR
 TRTDrow 2/TD/TR
 TRTDrow 3/TD/TR
 TRTDBug some word/TD/TR
 TRTDrow 4/TD/TR
 TRTDrow 5/TD/TR
 TRTDrow 6/TD/TR
/TABLE

this is solution:

#!/usr/bin/perl
use warnings;
use strict;
my $file;
while(){
   $file .= $_;
}

if ($file =~
m{(Bug(?:(?!TR).)*)/TR\s+(TR(?:(?!TR).)*/TR\s*){2}\/TABLE}s){
   print matched: $1\n;
}
else{
print failed\n;
}


this is run:
$ regex.pl file1.txt
matched: Bug some word/TD

$ regex32.pl file2.txt
failed


thanx everyone!

On 10/13/06, Paul Johnson [EMAIL PROTECTED] wrote:


On Fri, Oct 13, 2006 at 12:36:33PM -0500, Charles K. Clarkson wrote:

 I.B. wrote:

 : unfortunately I have to use regex to solve this problem.

 Why do you have to use a regex?

Because that is what the question stipulates.

--
Paul Johnson - [EMAIL PROTECTED]
http://www.pjcj.net

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response





Re: nice regular expression

2006-10-12 Thread Dr.Ruud
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