On Tue, May 6, 2014 at 10:30 PM, Danny Wong (dannwong)
<dannw...@cisco.com> wrote:
> Both string are possible outputs, so I want to be able to grep for the
> username only.

Well, if the username will always be either the only thing between
'by' and 'on', or in parens if it's not...

#! /usr/bin/env perl

use strict;
use warnings;
use 5.010;

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;
}

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to