in reply to How to substitute all tabs only in a specific field
Presuming you don't need to handle escapes (e.g. the closing quote character never will appear inside) you (probably) can get away with something simple along these lines (writing as a script for clarity; reducing it to perl -lnE left as an exercise):
use utf8; while( <> ) { chomp; my( $leader, $fields ) = m{\A (.*?) « \s* (.*?) \s* » \z}x; my @items = split( /\s+/, $fields ); say qq{$leader « }, join( q{,}, @items ), q{ »}; }
Edit: Tweaked the output, as you do have a couple spaces still in your output as hippo points out. One presumes you mean to canonicalise to pad with a single space around the joined items, but . . .
The cake is a lie.
The cake is a lie.
The cake is a lie.
|
|---|