Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/339.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C#Regex;双报价问题_C#_Regex_Double Quotes - Fatal编程技术网

C#Regex;双报价问题

C#Regex;双报价问题,c#,regex,double-quotes,C#,Regex,Double Quotes,我有点被难住了。我有这个方法,直到最近它还很有效: internal static bool IsZplFormat(string szString) { var regex = new Regex(@"\^XA.*\^XZ\\r\\n"); return regex.IsMatch(szString); } 考虑到以下字符串(取自我的单元测试),这将很好地工作: 现在发生的事情是,我得到了如下结果: const string zplSample = "^XA blah bla

我有点被难住了。我有这个方法,直到最近它还很有效:

internal static bool IsZplFormat(string szString)
{
    var regex = new Regex(@"\^XA.*\^XZ\\r\\n");
    return regex.IsMatch(szString);
}
考虑到以下字符串(取自我的单元测试),这将很好地工作:

现在发生的事情是,我得到了如下结果:

const string zplSample = "^XA blah blah \"blah ^XZ\r\n";
现在我的正则表达式不再匹配了

我认为
*
应该匹配所有字符,但它似乎被双引号绊倒了。关于如何让它再次工作,有什么想法吗?

在这里测试

string zplSample  = "^XA blah blah blah ^XZ\r\n";
string zplSample1 = "^XA blah blah \"blah ^XZ\r\n";

Console.WriteLine(new Regex(@"\^XA.*\^XZ\r\n").IsMatch(zplSample));
Console.WriteLine(new Regex(@"\^XA.*\^XZ\r\n").IsMatch(zplSample1));

Console.ReadKey();
输出

True
True
我改变了什么?将正则表达式模式转换为
@“^XA.*^XZ\r\n”
。(从两个
反斜杠到一个)(
\\r\\n

在这里测试

string zplSample  = "^XA blah blah blah ^XZ\r\n";
string zplSample1 = "^XA blah blah \"blah ^XZ\r\n";

Console.WriteLine(new Regex(@"\^XA.*\^XZ\r\n").IsMatch(zplSample));
Console.WriteLine(new Regex(@"\^XA.*\^XZ\r\n").IsMatch(zplSample1));

Console.ReadKey();
输出

True
True

我改变了什么?将正则表达式模式转换为
@“^XA.*^XZ\r\n”
。(从两个
反斜杠到一个)(
\\r\\n

失败的输入也是如此。
“^XA blah blah”blah^XZ\r\n”
?我想这是我困惑的一部分。当我进入调试器并“复制值”时,我所发布的字符串就是我得到的。失败的输入也是如此。
“^XA blah blah\”blah^XZ\r\n“
?我想这是我困惑的一部分。当我进入调试器并“复制值”OK时,我发布的字符串就是我得到的;也许是我在漫长的一天之后失去了它,但我看不出这两个正则表达式之间有什么区别;我正在失去它。忽略先前的注释OK;也许是我在漫长的一天之后失去了它,但我看不出这两个正则表达式之间有什么区别;我正在失去它。无视先前的评论