Record Line:
1,2,3,"four,for",5,"six,ssiixx","seven"
I want to remove the comma in "four,for" and "six,ssiixx". I tried using the $myValue =~ s/<regular_exp>/<replace_value>/g but I just end up replacing the string starting from the bad field to the last instance of a comma on the record.
Yahoo cut off my record string. Here it is again:
1,2,3,"four,for",5,"six,ssiixx","seven"
Once again, here is the full string with comma plus spacing afterwards:
1, 2, 3, "four, for", 5, "six, ssiixx", "seven"
I’m satisfied with raymanrevo’s answer but how do I choose "Best Answer"?
Here is a modified version of raymanrevo’s suggestion incorporating possible spacing:
$myValue =~ s/("[\w\ ]*),([\w\ ]*")//g;
Thank you raymanrevo! ![]()













It looks like you want to remove any commas inside quote characters. I don’t know Perl but I think Vim has a command similar to the Perl expression you wrote. You just need to make sure you regular expression is correct.
The matching expression makes sure that you have a double-quote followed by zero or more word characters followed by a comma, followed by zero or more word characters followed by a double-quote. Notice that it captures the everything around the comma (quotes included) in sub-expressions.
THE MATCHING REGEX:
/("\w*),(\w*")/
now for the replacement section, just reference your subpatterns.
/\1\2/g
So the full command in VIM becomes:
:%s/("\w*),(\w*")/\1\2/g
I ran this on the following string:
1,2,3,"four,for",5,"six,sixxxxx"
And the result:
1,2,3,"fourfor",5,"sixxxxx"
Hopefully you can just tweak the syntax support Perl’s flavor of regex replacement.
NOTE: You could also accomplish this with a lookahead AND lookbehind regex on the match to ONLY match the offending commas. Then you could simply replace the comma with an empty string. However, the syntax I think is quite a bit different between VIM and Perl for lookaheads and lookbehinds. Good luck!