On 4/7/06, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > On Fri, 07 Apr 2006 16:02:53 -0400, Oliver Block <[EMAIL PROTECTED]> > wrote: > >> I understand regex, but the following fails: > >> open PAGE, 'c://redcross.htm'; > >> while( my $line = <PAGE> ) { > >> $line =~ /Health and Safety Classes/ > >> print "$1\n"; > >> } > > > > What fails? Your forget a ';' after the regex but I guess that's not > > what you > > mean!? :) > > > Now that was pretty basic. So now that script runs, but I get the full > page. I was trying to limit the result to the words /Health and Safety > Classes/ that appear on the page. How do I get there?
$1 refers to the first parenthesized group in your regular expression. So if you change your code to look like: if ($line =~ /(Health and Safety Classes)/) { print "found a match: [$1]\n"; } then $1 will refer to the literal text inside the parens. Obviously, $1 matches more interesting things once you include some meta-characters. <http://perldoc.perl.org/perlre.html> -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>