in reply to RE: Quantifiers in regular expressions
in thread Quantifiers in regular expressions
Be sure to include the parenthesis around the entire regex that way it will save what it matches in $1.#!/usr/bin/perl while(<>) { chomp; # chomp so this next output is pretty. # newlines aren't discarded when you <> print "\"$1\" was matched out of \"$_\"" if m/(your_pattern)/; }
This will match "mywor" out of "myword"#!/usr/bin/perl while(<>) { chomp; print "\"$1\" was matched out of \"$_\"\n" if m/(\w{5}?)/; }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Re: RE: Quantifiers in regular expressions
by Roy Johnson (Monsignor) on May 19, 2004 at 20:25 UTC |