vivomancer has asked for the wisdom of the Perl Monks concerning the following question:
$reg used to be a regular expression contained in a single set of parens. Example: $reg = (K[STN]\w\w[GST]\w{1,2}[KRA]R[IVF]); But now I have set it up to automatically place parens around \w of variable length, so the previous $reg would now be: $reg = (K[STN]\w\w[GST])(\w{1,2})([KRA]R[IVF]); Such that a string searched against a regular expression with 1 variable length component would be split into 5 pieces. The stuff found before the match, constant length match1, variable length match, constant length match2, the stuff found after the match. I want to make it so a user could have any number of variable length regions. Is there a method with which I could add recursion?if($sequence[1] =~ m/^(.*)$reg(.*)$/i){ $aligned[$posCount][0] = $1; $aligned[$posCount][1] = $2; $aligned[$posCount][2] = $3; }
if($sequence[1] =~ m/^(.*)$reg(.*)$/i){ for(my $x = 0; $x < $numInsertionDeletes; $x++){ $aligned[$posCount][$x] = ????????; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Need a Method to add recursion to my regex
by tobyink (Canon) on Jun 18, 2012 at 19:28 UTC | |
by vivomancer (Initiate) on Jun 19, 2012 at 16:39 UTC | |
|
Re: Need a Method to add recursion to my regex
by choroba (Cardinal) on Jun 18, 2012 at 19:28 UTC |