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

Regular expression is sometimes found, at other times not. Why?

From:
Anette Seiler
Date:
March 6, 2002 05:47
Subject:
Regular expression is sometimes found, at other times not. Why?
Message ID:
3C862BE6.31911.14A8378@localhost
Hello,

I am struggling with a regular expression. I am using the regex-
program given in Learning Perl, 3rd expression, but the results are 
strange.

I want to match the word "Stand" in the following line:

<Li><!--: Stand:  2000-Oct-07, Eintrag in Digibib: 2000-Nov-16 :--
><!--... DATENBANKEN ...--><!--... VOLLTEXTE ...--><!--,, 
Sammlungen ,,--><A HREF="http://www.erlangerliste.uni-
erlangen.de" target="view_window">Erlanger Liste</a><BR><font 
size="2">(Linksammlung zu Germanistik, Malerei, Photographie 
und Computerkunst, Lexika; Browsen, Index und Volltext-Suche; 
Universit&auml;t Erlangen-N&uuml;rnberg, Institut f&uuml;r 
Germanistik)</FONT><BR><font size="1">Link-Check: 2001-Mrz-
09</FONT>


The regexprogram is:

#!/usr/bin/perl -w

use strict;

while (<>) {
    chomp;
    if (/Stand/) {
        print "Matched: |$`<$&>$'|\n";
    } else {
        print "No match.\n";
    }

}

When I run the program with the line of text given above I get the 
result:

No match

However, If I run part of the line above against the program, e.g.,

<Li><!--: Stand:  2000-Oct-07, Eintrag in Digibib: 2000-Nov-16 :--
><!--... DATENBANKEN ...--><!--... VOLLTEXTE ...--><
!--,, Sammlungen ,,-->

I get the correct answer. 

If I search for the regex .* against the full line, I expect to get the 
whole full line as an answer. But it matches only:

Matched: |<mlung zu Germanistik, Malerei, Photographie und 
Computerkunst, Lexika; Browsen, Index und Volltext-Suche; 
Universit&auml;t Erlangen-N&uuml;rnberg, Institut f&uuml;r 
Germanistik)</FONT><BR><font size="1">Link-Check: 2001-Mrz-
09</FONT>>|

Why is this so?

asks a puzzled

Anette





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