throop has asked for the wisdom of the Perl Monks concerning the following question:
I've been doing it with a three step process - pull off the numbers, pull off the A and B's, clean up the nulls1.2.3AAABB,AAB,AA,AAABBB should give qw(1.2.3 AAA BB AA B AA AAA BBB) AABB,AAAB,ABBB should give qw(AA BB AAA B A BBB)
(I've omitted the extra code that does the error-checking etc.) I want to do a regular match on the numbers, then a greedy match on the rest. I don't think what I did is particularly clear or clean. Is there a way to do this in a single, comprehensible regex, without using something like grep to clean up the null strings?use strict; sub chip{ local($_)=@_; if(/^(\d+ (?: \.\d+)* )? (.+) /x){ my($front) = $1; if(my(@rest) = $2 =~ /(A+) (B*) ,? /gx){ unshift(@rest, $front); grep {$_} @rest}}}
throop
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: g matching after a single regular match
by GrandFather (Saint) on Feb 01, 2007 at 21:25 UTC | |
|
Re: g matching after a single regular match
by ikegami (Patriarch) on Feb 01, 2007 at 21:26 UTC | |
by Roy Johnson (Monsignor) on Feb 01, 2007 at 23:00 UTC | |
|
Re: g matching after a single regular match
by AltBlue (Chaplain) on Feb 01, 2007 at 21:26 UTC | |
|
Re: g matching after a single regular match
by johngg (Canon) on Feb 01, 2007 at 21:28 UTC | |
|
Re: g matching after a single regular match
by ikegami (Patriarch) on Feb 01, 2007 at 21:43 UTC |