in reply to Re: Perl Regex
in thread Perl Regex

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.

Replies are listed 'Best First'.
Re^3: Perl Regex
by pbeckingham (Parson) on Jul 08, 2004 at 13:52 UTC

    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.

        I gave you a regex that attempts to locate your data in your input. Then you asked for output in a particular form, and I gave you that. Now you're saying it's wrong for some other reason.

        Can you not modify the sample code to suit your needs? Or could you post your own code, showing the effort you have made?

Re^3: Perl Regex
by Roy Johnson (Monsignor) on Jul 08, 2004 at 13:52 UTC
    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.