in reply to How to improve regex for parsing equals delimited data

Use split, then zap the empty first field.
The idea is that the delimiter is not just "=", but something like " FIELDx = ".
my @fld = split /\s*FIELD\w = /; shift @fld; # Zap empty first field print join(",",@fld ),"\n";

             I hope life isn't a big joke, because I don't get it.
                   -SNL

Replies are listed 'Best First'.
Re^2: How to improve regex for parsing equals delimited data
by sauoq (Abbot) on May 11, 2012 at 03:48 UTC

    Same idea in one operation, a little more robust, and using his original [A-Za-z]+ for fields...

    my ($toss, @list) = split /\s*[A-Za-z]+\s*\=\s*/;

    -sauoq
    "My two cents aren't worth a dime.";
Re^2: How to improve regex for parsing equals delimited data
by jwkrahn (Abbot) on May 11, 2012 at 03:46 UTC
    my @fld = split /\s*FIELD\w = /; shift @fld; # Zap empty first field print join(",",@fld ),"\n";
    my @fld = /FIELD\w\s*=\s*(\S+)/g; print join( ',', @fld ), "\n";

      His fields can have spaces: "SOH: 169879251".

      -sauoq
      "My two cents aren't worth a dime.";
        my @fld = map /=s*(.+)/, /\b +\b/g; print join( ',', @fld ), "\n";

        Update: Thanks Lotus1, it should be:

        my @fld = map /=\s*(.+)/, split /\b +\b/; print join( ',', @fld ), "\n";
Re^2: How to improve regex for parsing equals delimited data
by Lotus1 (Vicar) on May 11, 2012 at 14:34 UTC

    Thanks, this worked well. I tried split at one point but didn't realize everything was shifted by one so I missed the fourth field. This is easy to follow also.