in reply to Perl Regex

How about:

my @matches = $string =~ / ^ # beginning of line (\d{1,5}) # 1-5 digit number \s+ # gap (?: # group ([A-Z0-9()-]{7}) # 7-char thing \s+ # gap ([A-Z0-9()-]{7}) # another 7-char thing ){1,45} # 7-char thing # up to 45 groups $ # end of line /gx;
Update: Added /g to regex. Oops.

Replies are listed 'Best First'.
Re^2: Perl Regex
by Anonymous Monk on Jul 08, 2004 at 13:41 UTC
    This looks good, except that I want to be able to do the following:

    Convert:

    14 ASN1 YGR124W ASN1 YPR145W

    to :

    14 1 ASN1 YGR124W

    14 2 ASN1 YPR145W

    or whatever variation is possible given the previously stated row possibilities.

      Okay, then perhaps this:

      my @matches = $string =~ / ^ # beginning of line (\d{1,5}) # 1-5 digit number \s+ # gap (?: # group ([A-Z0-9()-]{7}) # 7-char thing \s+ # gap ([A-Z0-9()-]{7}) # another 7-char thing ){1,45} # 7-char thing # up to 45 groups $ # end of line /gx; my $first = shift @matches; my $count = 1; while (@matches) { print $first, ' ', $count, ' ', shift @matches, ' ', shift @matches, "\n"; $count++; }

        But the first and second rows of the product were originally on the same row.
      my ($marker, @pairs) = split; my $c = 0; while (@pairs) { ++$c; my ($thing1, $thing2) = splice(@pairs, 0, 2); print "$marker $c $thing1 $thing2\n"; }

      We're not really tightening our belts, it just feels that way because we're getting fatter.