3 回答
TA贡献1802条经验 获得超5个赞
它帮助我看到我需要采取分阶段的方法。
首先,我得到 ," 和 ",. 然后我找到了在它们出现的模式中有单双引号的模式,并用 2 个双引号和一个空格替换。以防万一,我每次都这样做。
string matchPattern = "((?<=,\").*?(?=\",))";
string input = "something not qualified,\"12\" x 12\" something qualified, becuase it has a comma\",this one is not qualified and needs no fixing a 12\" x 12\",\"8\" X 8\" sign, plain\",one more";
var newLine = input;
Regex regx = new Regex(matchPattern);
Regex regxReplace = new Regex(@"(?<=\w)""[^\w|\""]");
var matches = regx.Matches(input);
foreach (Match matchingString in matches)
{
var value = matchingString.Value;
if (regxReplace.IsMatch(value))
{
changed = true;
var newReplacementString = regxReplace.Replace(value, "\"\" ");
newLine = newLine.Replace(matchingString.Value, newReplacementString);
}
}
return newLine;
- 3 回答
- 0 关注
- 221 浏览
添加回答
举报