G'day Xuo,
There are a lot a problems with your post:
-
title has "tabs" but description has "<tabs/space>"
-
data has guillemets but description has "<double quotes>"
-
you're not substituting whitespace just after the opening quote and just before the closing quote
(++hippo already commented on this)
-
you've failed to use <code> tags so we can't see the number of whitespace characters:
HTML converts strings of spaces and tabs into a single space
Please read "How do I post a question effectively?" carefully.
So, with a lot of guessswork, I believe the following technique, succinctly and efficiently, does what you want:
$ perl -pE 's/^[^"]+"\s+(.+)\s+"/$1 =~ y{ \t}{,}rs/e'
a b " x1 x2 "
x1,x2
c d " x3 "
x3
e f " x4 x5 x6 x7 "
x4,x5,x6,x7
x y z " 1space 2spaces spacetabspace end "
1space,2spaces,spacetabspace,end
The 'r' modifier was introduced in Perl v5.14:
see "perl5140delta: Non-destructive substitution".
Attempting to modify $1 directly results in a "Modification of a read-only value" fatal error.
If you have a earlier version of Perl, you'll need to use an interim variable; perhaps something like this:
$ perl -pe 's/^[^"]+"\s+(.+)\s+"/($x = $1) =~ y{ \t}{,}s; $x/e'
a b " x1 x2 "
x1,x2
c d " x3 "
x3
e f " x4 x5 x6 x7 "
x4,x5,x6,x7
x y z " 1space 2spaces spacetabspace end "
1space,2spaces,spacetabspace,end
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.