最后,我要替换包含在\t
中的所有"
我目前正在Regex101上尝试我的正则表达式的各种迭代...这是我到目前为止最接近的迭代器...
originString = blah\t\"blah\tblah\"\t\"blah\"\tblah\tblah\t\"blah\tblah\t\tblah\t\"\t\"\tbleh\"
regex = \t?+\"{1}[^"]?+([\t])?+[^"]?+\"
\t?+ maybe one or more tab
\"{1} a double quote
[^"]?+ anything but a double quote
([\t])?+ capture all the tabs
[^"]?+ anything but a double quote
\"{1} a double quote
我的逻辑有缺陷!我需要您对标签字符进行分组的帮助。
仅使用"[^"]+"
正则表达式来匹配双引号的子字符串(如果没有要解释的转义序列,并且仅在匹配评估器内部替换匹配内的选项卡:
var str = "A tab\there \"inside\ta\tdouble-quoted\tsubstring\" some\there";
var pattern = "\"[^\"]+\""; // A pattern to match a double quoted substring with no escape sequences
var result = Regex.Replace(str, pattern, m =>
m.Value.Replace("\t", "-")); // Replace the tabs inside double quotes with -
Console.WriteLine(result);
// => A tab here "inside-a-double-quoted-substring" some here
请参见C# demo