in reply to regex pattern match
Unless you have reason to split the first n-1 pieces as well, you only need the last one separated.
Once you have it, you replace the commata with quote, newline, appropriate number of spaces, quote
Voila!
while(<DATA>) { chomp; my ($first, $last ) = /(.+",)(.+)/; print $first; $first = " " x length( $first ); $last =~ s/,/"\n$first"/g; print "$last\n"; } __DATA__ "A","B","C","D" "A","B","C","D,E,F" "A","B","C","D" "A","B","C","D,R,T"
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: regex pattern match
by McA (Priest) on Mar 29, 2013 at 10:15 UTC | |
by hdb (Monsignor) on Mar 29, 2013 at 10:20 UTC |