string matching doesn"t work

string matching doesn"t work

am 01.11.2007 22:48:44 von jack

Hello, I have a little problem. i am trying to extract some text from
a file. I need to get the first names and last names as well as the
data between the tags which corresponds to Current Status. For
example:

Mr. firstname lastname


Current Status class="profile" colspan="2">Some data

so i need firstname lastname as well as some data. my current string
looks like this but it doesn't work.

if (@content =~ m/

Mr.*<\/h1>/){
print "here " . $1;
}

Please help....

Re: string matching doesn"t work

am 01.11.2007 22:53:31 von Mirco Wahab

Jack wrote:
> Hello, I have a little problem. i am trying to extract some text from
> a file. I need to get the first names and last names as well as the
> data between the tags which corresponds to Current Status. For
> example:
>
>

Mr. firstname lastname


> Current Status > class="profile" colspan="2">Some data
> so i need firstname lastname as well as some data. my current string
> looks like this but it doesn't work.
> if (@content =~ m/

Mr.*<\/h1>/){
> print "here " . $1;
> }


If you use this more often and in a production
environment, you might be better of after
learning one of the HTML-Parser modules:

http://search.cpan.org/~gaas/HTML-Parser-3.56/

But if its only an occasional thing to do,
you can built a regular expression for
extraction, like:

...

my $html='

Mr. firstname lastname


Current Status
Some data
';

my $expr = qr{

([^<]+)

# stuff in h1 => $1
.+? # jump to the next td
]+> ([^<]+) # stuff in td => $2
}sx;


print "h1 => |$1|, td => |$2|\n" while $html =~ /$expr/g;

...

Regards

M.

Re: string matching doesn"t work

am 01.11.2007 22:56:47 von Lars Eighner

In our last episode,
<1193953724.538513.117370@y27g2000pre.googlegroups.com>, the lovely and
talented Jack broadcast on comp.lang.perl.misc:

> Hello, I have a little problem. i am trying to extract some text from
> a file. I need to get the first names and last names as well as the
> data between the tags which corresponds to Current Status. For
> example:

>

Mr. firstname lastname


>Current Status > class="profile" colspan="2">Some data

> so i need firstname lastname as well as some data. my current string
> looks like this but it doesn't work.

> if (@content =~ m/

Mr.*<\/h1>/){
> print "here " . $1;
> }

> Please help....


perldoc -q matching

--
Lars Eighner
Countdown: 445 days to go.
What do you do when you're debranded?

Re: string matching doesn"t work

am 01.11.2007 23:23:23 von Mahesh M

On Nov 1, 2:48 pm, Jack wrote:
> Hello, I have a little problem. i am trying to extract some text from
> a file. I need to get the first names and last names as well as the
> data between the tags which corresponds to Current Status. For
> example:
>
>

Mr. firstname lastname


> Current Status > class="profile" colspan="2">Some data
>
> so i need firstname lastname as well as some data. my current string
> looks like this but it doesn't work.
>
> if (@content =~ m/

Mr.*<\/h1>/){
> print "here " . $1;
> }
>
> Please help....

I would use something like the HTML::TreeBuilder module to extract
information out of HTML data.

If you want to stick with pattern matching, following should be
informative:

perldoc perlretut (or http://perldoc.perl.org/perlretut.html)
perldoc perlre (or http://perldoc.perl.org/perlre.html)

HTH,
Mahesh.

Re: string matching doesn"t work

am 01.11.2007 23:43:21 von Tad McClellan

Jack wrote:

> if (@content =~ m/

Mr.*<\/h1>/){


The match operator works on a string, not on an array.


--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"

Re: string matching doesn"t work

am 01.11.2007 23:47:15 von rvtol+news

Jack schreef:

> if (@content =~ m/

Mr.*<\/h1>/){
> print "here " . $1;
> }

$ perl -le'
# use warnings;
@c = qw(abc de fghi);
if (@c =~ /([bdg0-9])/) {
print $1;
}
'
3

--
Affijn, Ruud

"Gewoon is een tijger."

Re: string matching doesn"t work

am 02.11.2007 18:32:10 von jack

On Nov 1, 3:47 pm, "Dr.Ruud" wrote:
> Jack schreef:
>
> > if (@content =~ m/

Mr.*<\/h1>/){
> > print "here " . $1;
> > }
>
> $ perl -le'
> # use warnings;
> @c = qw(abc de fghi);
> if (@c =~ /([bdg0-9])/) {
> print $1;
> }
> '
> 3
>
> --
> Affijn, Ruud
>
> "Gewoon is een tijger."



I used Mirco Wahab's solution and it worked for some of the cases but
now I am stuck at parsing this line.

Address
City State  V2X
6J3
Canada


Phone: b>555-555-5555 



I want to parse each section into a variable using qr. so for the
Address I used
]+> ([^<]+)
# this line works fine and I get the address
portion
.+?

([^&]+)  \; # this part doesn't work meaning that I
don't get anything for city

Any help would much appreciated.

Re: string matching doesn"t work

am 02.11.2007 19:19:24 von Jim Gibson

In article <1194024730.026878.43090@z24g2000prh.googlegroups.com>, Jack
wrote:


> I used Mirco Wahab's solution and it worked for some of the cases but
> now I am stuck at parsing this line.
>
> Address
City State  V2X
> 6J3
Canada

>
> Phone: > b>555-555-5555 
>
>
>
> I want to parse each section into a variable using qr. so for the
> Address I used
> ]+> ([^<]+)
# this line works fine and I get the address
> portion
> .+?
>
([^&]+)  \; # this part doesn't work meaning that I
> don't get anything for city
>
> Any help would much appreciated.

If you want help with a program, you need to post a complete, working,
short-as-possible version that demonstrates the problem you are having.

You are running up against the problem of parsing HTML with regular
expressions. Mirco's code was for a very simple case. As your actual
cases become more complex, you have to add more complexity to your REs.

Maybe it is time to consider Mirco's first recommendation: learn to use
an HTML-parsing module, such as HTML::Parser.

--
Jim Gibson

Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com