Please find below the tested code, same regular expression match both the patterns:
my $string1 = "^Modifications made by Danny Wong (danwong) on 2014/05/06 18:27:48 from database brms"; my $string2 = "^Modifications made by danwong on 2014/05/06 18:27:48 from database brms"; if ($string1=~/by.*\s\(?(\w+)\)?\s+on/) { print " String1 Matched\n" } if ($string2=~/by.*\s\(?(\w+)\)?\s+on/) { print " String2 Matched\n" } Output: String1 Matched String2 Matched Hope it will help! Thanks, Vishal > Date: Wed, 7 May 2014 01:46:09 -0400 > From: u...@stemsystems.com > To: beginners@perl.org > Subject: Re: regular expression > > On 05/07/2014 01:40 AM, John SJ Anderson wrote: > > > > > my @strings = ( > > "^Modifications made by Danny Wong (danwong) on 2014/05/06 18:27:48 > > from database brms" , > > "^Modifications made by danwong on 2014/05/06 18:27:48 from database > > brms²", > > ); > > > > foreach my $string ( @strings ) { > > my( $match ) = $string =~ /by (.*?) on/; > > if ( $match and $match =~ /\(([^)]+)\)/ ) { > > $match = $1; > > } > > say "Matched '$1' in '$string'" > > if $match; > > } > > > > i would go with just getting the word before an optional ), then 'on' > and the year. untested: > > my $match = $string =~ /(\w+)\)?\s+on\s+\d+/ ; > > uri > > -- > Uri Guttman - The Perl Hunter > The Best Perl Jobs, The Best Perl Hackers > http://PerlHunter.com > > -- > To unsubscribe, e-mail: beginners-unsubscr...@perl.org > For additional commands, e-mail: beginners-h...@perl.org > http://learn.perl.org/ > >