develooper Front page | perl.beginners | Postings from February 2002

RE: pattern matching question

Thread Previous | Thread Next
From:
Jason Larson
Date:
February 28, 2002 10:30
Subject:
RE: pattern matching question
Message ID:
9F560B2FB311D6119A7D00204840E2059F20F1@swbtexch2.swbanktx.com
-----Original Message-----
From: bob ackerman [mailto:rdacker@pacbell.net]
Sent: Thursday, February 28, 2002 11:32 AM
To: richard noel fell
Cc: beginners@perl.org
Subject: Re: pattern matching question

On Thursday, February 28, 2002, at 08:37  AM, richard noel fell wrote:

> while (defined($Line=<In2>)){
>   if($Line=~/(\(D\d+\))\s*(\w*)/){
> print "==> $2\n";
> };
> };
>

disclaimer: i am a rank newbot
if i replace '/w*' with '.*$'
i get desired text.
looks like \w* doesn't do what we expect.
problems with \t in lines?
--------------------------
I'm also new to Perl, so I won't correct your typo, but I will point out a
problem in your statement: "looks like \w* doesn't do what we expect."  I'm
not sure who "we" is, but this does exactly what is expected.  '\w*' matches
zero or more word characters.  The problem with the match is that the white
space in the lines was followed by non-word characters ('-' and '/').  A
word character is any letter, number, or underscore.  Your match with '.*'
works because that matches zero or more of ANY character.
As for the question: "problems with \t in lines?", that should not make any
difference to the match, because '\s*' would match the tabs, as tabs are
considered whitespace characters.

HTH!
Jason


CONFIDENTIALITY NOTICE:

************************************************************************

The information contained in this ELECTRONIC MAIL transmission
is confidential.  It may also be privileged work product or proprietary
information. This information is intended for the exclusive use of the
addressee(s).  If you are not the intended recipient, you are hereby
notified that any use, disclosure, dissemination, distribution [other
than to the addressee(s)], copying or taking of any action because
of this information is strictly prohibited.

************************************************************************

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About