Both string are possible outputs, so I want to be able to grep for the
username only.

I tried this, but it works for the string without parentheses.

"^Modifications made by danwong on 2014/05/06 18:27:48 from database brms",


$str1 =~ /by.*?[(]?(.*?)[)]?\s+on/i;


The one with partheses gives me this output.

$1 is Danny Wong (danwong
yes the last ) is missing, so it looks like I’m close, I’m not exactly
sure what is missing.



On 5/6/14, 10:25 PM, "John SJ Anderson" <geneh...@genehack.org> wrote:

>On Tue, May 6, 2014 at 10:19 PM, Danny Wong (dannwong)
><dannw...@cisco.com> wrote:
>
>> What is a regular expression where I can extract ³danwong² from either
>> string (one string have () parentheses and the other doesn¹t have
>> parentheses)?
>
>I'm not entirely sure what you're trying to accomplish, but perhaps
>something like:
>
>#! /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 ) {
>  say "Matched '$1' in '$string'"
>    if $string =~ /(danwong)/;
>}
>
>-- 
>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