in reply to Re: Quick regex
in thread Quick regex

that looks good, but how do i kill the trailing _ So your example would look like this 'fred_bill_john'

Replies are listed 'Best First'.
Re^3: Quick regex
by ikegami (Patriarch) on Nov 24, 2009 at 18:00 UTC

    You want to match

    name, dash, name, dash, name

    or

    ( name, dash ) x 2, name

    so

    my ($substr) = $s =~ /^((?:[^_]*_){2}[^_]*)/ or die("No match\n");
Re^3: Quick regex
by Anonymous Monk on Nov 24, 2009 at 17:41 UTC
    Everything in ( ) goes into $1, so move the last _ outside of )