in reply to Perl Regex

Well, /.*/ will match it. But you haven't said what you want to do with the rest.

Part of the problem with regular expressions is just being able to say what it is you want to do. You need to solve that before we can help with a more detailed match.

-- Randal L. Schwartz, Perl hacker
Be sure to read my standard disclaimer if this is a reply.

Replies are listed 'Best First'.
Re^2: Perl Regex
by Anonymous Monk on Jul 08, 2004 at 17:41 UTC
    I want to do something along the lines of
    #! perl -w scipt use strict; use warnings; # open a file for reading in the current directory open(FILEHANDLE,"< input_file.txt"); open(OUTFILE,"+> outfile_file.txt"); my $record_count = 0; while (<FILEHANDLE>){ if ($_ =~ /^(\d{1,5})\s+ (?:([A-Z0-9()-]{2,15})\s+([A-Z0-9()-]{7})){1} (?:([A-Z0-9()-]{2,15})\s+([A-Z0-9()-]{7})){0,1} (?:([A-Z0-9()-]{2,15})\s+([A-Z0-9()-]{7})){0,1} (?:([A-Z0-9()-]{2,15})\s+([A-Z0-9()-]{7})){0,1} (?:([A-Z0-9()-]{2,15})\s+([A-Z0-9()-]{7})){0,1} (?:([A-Z0-9()-]{2,15})\s+([A-Z0-9()-]{7})){0,1} (?:([A-Z0-9()-]{2,15})\s+([A-Z0-9()-]{7})){0,1} (?:([A-Z0-9()-]{2,15})\s+([A-Z0-9()-]{7})){0,1} (?:([A-Z0-9()-]{2,15})\s+([A-Z0-9()-]{7})){0,1} (?:([A-Z0-9()-]{2,15})\s+([A-Z0-9()-]{7})){0,1} (?:([A-Z0-9()-]{2,15})\s+([A-Z0-9()-]{7})){0,1} (?:([A-Z0-9()-]{2,15})\s+([A-Z0-9()-]{7})){0,1} (?:([A-Z0-9()-]{2,15})\s+([A-Z0-9()-]{7})){0,1} (?:([A-Z0-9()-]{2,15})\s+([A-Z0-9()-]{7})){0,1} (?:([A-Z0-9()-]{2,15})\s+([A-Z0-9()-]{7})){0,1} (?:([A-Z0-9()-]{2,15})\s+([A-Z0-9()-]{7})){0,1} (?:([A-Z0-9()-]{2,15})\s+([A-Z0-9()-]{7})){0,1} (?:([A-Z0-9()-]{2,15})\s+([A-Z0-9()-]{7})){0,1} (?:([A-Z0-9()-]{2,15})\s+([A-Z0-9()-]{7})){0,1} (?:([A-Z0-9()-]{2,15})\s+([A-Z0-9()-]{7})){0,1} (?:([A-Z0-9()-]{2,15})\s+([A-Z0-9()-]{7})){0,1} (?:([A-Z0-9()-]{2,15})\s+([A-Z0-9()-]{7})){0,1} (?:([A-Z0-9()-]{2,15})\s+([A-Z0-9()-]{7})){0,1} (?:([A-Z0-9()-]{2,15})\s+([A-Z0-9()-]{7})){0,1} (?:([A-Z0-9()-]{2,15})\s+([A-Z0-9()-]{7})){0,1} (?:([A-Z0-9()-]{2,15})\s+([A-Z0-9()-]{7})){0,1} (?:([A-Z0-9()-]{2,15})\s+([A-Z0-9()-]{7})){0,1} (?:([A-Z0-9()-]{2,15})\s+([A-Z0-9()-]{7})){0,1} (?:([A-Z0-9()-]{2,15})\s+([A-Z0-9()-]{7})){0,1} (?:([A-Z0-9()-]{2,15})\s+([A-Z0-9()-]{7})){0,1} (?:([A-Z0-9()-]{2,15})\s+([A-Z0-9()-]{7})){0,1} (?:([A-Z0-9()-]{2,15})\s+([A-Z0-9()-]{7})){0,1} (?:([A-Z0-9()-]{2,15})\s+([A-Z0-9()-]{7})){0,1} (?:([A-Z0-9()-]{2,15})\s+([A-Z0-9()-]{7})){0,1} (?:([A-Z0-9()-]{2,15})\s+([A-Z0-9()-]{7})){0,1} (?:([A-Z0-9()-]{2,15})\s+([A-Z0-9()-]{7})){0,1} (?:([A-Z0-9()-]{2,15})\s+([A-Z0-9()-]{7})){0,1} (?:([A-Z0-9()-]{2,15})\s+([A-Z0-9()-]{7})){0,1} (?:([A-Z0-9()-]{2,15})\s+([A-Z0-9()-]{7})){0,1} (?:([A-Z0-9()-]{2,15})\s+([A-Z0-9()-]{7})){0,1} (?:([A-Z0-9()-]{2,15})\s+([A-Z0-9()-]{7})){0,1} (?:([A-Z0-9()-]{2,15})\s+([A-Z0-9()-]{7})){0,1} (?:([A-Z0-9()-]{2,15})\s+([A-Z0-9()-]{7})){0,1} (?:([A-Z0-9()-]{2,15})\s+([A-Z0-9()-]{7})){0,1} (?:([A-Z0-9()-]{2,15})\s+([A-Z0-9()-]{7})){0,1} (?:([A-Z0-9()-]{2,15})\s+([A-Z0-9()-]{7})){0,1} (?:([A-Z0-9()-]{2,15})\s+([A-Z0-9()-]{7})){0,1} $/gx){ $record_count++; my $1st = $1; my $2st = $2; my $3st = $3; my $4st = $4; my $5st = $5; my $6st = $6; my $7st = $7; my $8st = $8; my $9st = $9; my $10st = $10; my $11st = $11; my $12st = $12; my $13st = $13; my $14st = $14; my $15st = $15; my $16st = $16; my $17st = $17; my $18st = $18; my $19st = $19; my $20st = $20; my $21st = $21; my $22st = $22; my $23st = $23; my $24st = $24; my $25st = $25; my $26st = $26; my $27st = $27; my $28st = $28; my $29st = $29; my $30st = $30; my $31st = $31; my $32st = $32; my $33st = $33; my $34st = $34; my $35st = $35; my $36st = $36; my $37st = $37; my $38st = $38; my $39st = $39; my $40st = $40; my $41st = $41; my $42st = $42; my $43st = $43; my $44st = $44; my $45st = $45; my $46st = $46; my $47st = $47; my $48st = $48; my $49st = $49; my $50st = $50; my $51st = $51; my @array_of_gene_records = ($2st, $3st, $4st, $5st, $6st, $7st, + $8st, $9st, $10st, $11st, $12st, $13st, $14st, $15st, $15, $16st, $1 +7st, $18st, $19st, $20st, $21st, $22st, $23st, $24st, $25st, $26st, $ +27st, $28st, $29st, $30st, $31st , $32st , $33st, $34st, $35st, $36st +, $37st, $38st, $39st, $40st, $41st, $42st, $43st, $44st, $45st, $46s +t, $47st, $48st, $49st, $50st, $51st); my $subrecord_id = 1; foreach (@array_of_gene_records){ print OUTFILE "$record_count\t$1st\t$subrecord_id\t$_\n"; $subrecord_id++; } } }

      Wow. That's very simliar to what I was trying to accompish just yesterday in the CB.

      See dcvr69's scratchpad for how I solved my particular problem... I think it would apply to you situation as well with a little tweaking.

      If someone finds a way to do it in a single match I'd love to know about it. I couldn't find a way to use (?:()())+ to return multiple captures to an array. /g wouldn't work because of a prefix capture earlier in the pattern.

      Basically, my (working but not happy with it) solution was to capture the prefix and the remainder in one match, and then do the variable element capture on the remainder with /g in array context.

      I just feel like I'm missing something about RE that would allow both steps in one match/capture, without resorting to sub calls inside the pattern or other hacks that would end up being worse that the two stage solution I have now.

Re^2: Perl Regex
by Anonymous Monk on Jul 08, 2004 at 15:36 UTC
    Please refer to my other post in addition to the first.