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

RE: pattern matching question

Thread Previous | Thread Next
Jason Larson
February 28, 2002 10:30
RE: pattern matching question
Message ID:
-----Original Message-----
From: bob ackerman []
Sent: Thursday, February 28, 2002 11:32 AM
To: richard noel fell
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.




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 Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About