Search Question

R

Reinhard Glauber

Ok, the wget problem is solved, but now I have a search Problem

I have $text which contains Text :)
If he finds "E-Mail", then he cuts the whole line and prints it.

if ($html =~ /E-Mail.*\n/)
{
print "$&\n";
}


What I want to do now is, that Perl grabs 5 lines BEFORE the occurance of E-Mail.

Perl Gmbh
Munichstreet 5
80802 Munich
Tel.: 9038429038/38420384
E-Mail: (e-mail address removed)

So Perl should cut all the 4 Lines befor E-Mail and put it into an array, or something like that.

I dont need the whole code, just some tips how to do that

THANKS
 
D

Dr.Ruud

Reinhard Glauber schreef:
if ($html =~ /E-Mail.*\n/)
{
print "$&\n";
}

What I want to do now is, that Perl grabs 5 lines BEFORE the
occurance of E-Mail.

Or 4 lines before:

print $1 if $html =~ /(.*\n)(?:.*\n){3}E-Mail.*/;
 
G

Gunnar Hjalmarsson

Reinhard said:
Ok, the wget problem is solved, but now I have a search Problem

I have $text which contains Text :)
If he finds "E-Mail", then he cuts the whole line and prints it.

if ($html =~ /E-Mail.*\n/)
{
print "$&\n";
}

Then you solved your search problem, right?
What I want to do now is, that Perl grabs 5 lines BEFORE the occurance of E-Mail.

Then you need to tell Perl to do that.

- Which efforts did you make to complete the task before asking for help
here?
- Where is the code showing your best shot?
- Have you read the posting guidelines for this group, as Sinan
suggested in the other thread?
 
R

Reinhard Glauber

Dr.Ruud said:
Reinhard Glauber schreef:


Or 4 lines before:

print $1 if $html =~ /(.*\n)(?:.*\n){3}E-Mail.*/;


that works :) thank you

but what means (?:.*\n)
 
G

Gunnar Hjalmarsson

Reinhard said:
that works :) thank you

but what means (?:.*\n)

Yes, how rude of you, Dr. Ruud, to not thoroughly explain every detail
of the expression you posted!!
 
M

Matt Garrish

Reinhard Glauber said:
that works :) thank you

but what means (?:.*\n)

You should be quite capable of looking it up in perlre under the extended
patterns section.

Matt
 
D

Dr.Ruud

Reinhard Glauber schreef:
Dr.Ruud:
Reinhard Glauber:

Or 4 lines before:
print $1 if $html =~ /(.*\n)(?:.*\n){3}E-Mail.*/;

that works [...] but what means (?:.*\n)

This is similar: /(.*\n)(.*\n){3}E-Mail.*/
Check `perldoc perlre` for the details.
 
J

John Bokma

Reinhard Glauber said:
sorry, I'm a Perl newbie
Is this Newsgroup just for the Elite ?

Is this newsgroup just to repeat everything that is clearly documented,
and if you're serious at learning Perl *should* learn (probably by
yourself) at some time in the very near future?
 
T

Tad McClellan

Reinhard Glauber said:
Is this Newsgroup just for the Elite ?


No, but it is hoped that people would spend 10 minutes trying to
find the answer on their own before asking hundreds/thousands
of people around the world about it.

Perl's regular expressions are documented in

perldoc perlrequick
perldoc perlretut
perldoc perlre


It is also hoped that you would not ask hundreds of people to bother
explaining parts that you _do_ already understand.

Which parts do you not understand?

dot (.) matches any character.

asterisk (*) matches zero or more of the previous thing.

\n matches a newline.

(?: ) does grouping, like parenthesis, but without triggering memory.
 
D

David H. Adler

dot (.) matches any character.

Um... not unless you're following damian's advice to use the /s modifier
at all times. Under normal circumstances it matches any character
*except a newline*.

dha
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top