我试图从HTML响应中提取引用的文本.但是,当我使用正则表达式匹配数据时,我收到错误消息"无法识别的转义序列".代码粘贴在下面.我错过了一些基本的东西吗?
static private string ParseText2GetLink(string response)
{
Match match = Regex.Match( response, @"("[^"]*\.csv")" );
string key = null;
// Here we check the Match instance.
if (match.Success)
{
// Finally, we get the Group value and display it.
key = match.Groups[1].Value;
Console.WriteLine(key);
}
return key;
}
Run Code Online (Sandbox Code Playgroud)
要在@""字符串中包含双引号,您必须将其加倍:
@"(""[^""]*\.csv"")"
Run Code Online (Sandbox Code Playgroud)
或者您可以使用普通字符串:
"(\"[^\"]*\\.csv\")"
Run Code Online (Sandbox Code Playgroud)
(注意,现在你必须逃避反斜杠.)
| 归档时间: |
|
| 查看次数: |
302 次 |
| 最近记录: |