Re: Regexp Basics

2006-10-03 Thread Sijo George
Else try This.. #!/usr/local/bin/perl use strict; my $string = "Theres more than 1 way to do it"; if ($string =~ /\w+$/){ print "Hooray! pattern found\n"; print $&; } Use the inbuilt perl variables.. $` prints the pre matching part, $& gives the matched variale and $' gives the post matching pa

RE: Regexp Basics

2006-10-02 Thread Thomas Bätzler
Michael Alipio <[EMAIL PROTECTED]> asked: > #!/usr/local/bin/perl > use strict; > > my $string = "Theres more than 1 way to do it"; if ($string > =~ /\w+$/){ print "Hooray! pattern found"; print $1; } > > My goal is to print the last word. > However, it only prints "Hooray! pattern found"; > >

RE: Regexp Basics

2006-10-02 Thread Lee Goddard
> #!/usr/local/bin/perl > use strict; > > my $string = "Theres more than 1 way to do it"; if ($string > =~ /\w+$/){ print "Hooray! pattern found"; print $1; } You need to wrap the bit you wish to extract in (paremphasis) and it'll be put into $1. If you do two (wraps), you'll get $1 and $2, and