[英]C# Regex not returning
我正在研究一个练习问题,它给了我更长的琴弦。 我需要将字符串从引号中拉出(wh
// names is a string[] composed of names like these: "BOB", "JOE", "FRANK", etc...
// (the ""s are part of the string, not string designations). I suppose that makes them "\"Bob\"", etc...
foreach(string name in names)
{
Regex regex = new Regex("/\"(.+)\"/");
Match match = regex.Match(name);
Console.WriteLine (match.Value);
if (match.Success)
{
Console.WriteLine("string: {0} and match value: {1}", name, match.Groups[1].Value);
}
}
我什么都没注销。 我尝试了几种引用.Value
方法,但是我也无法记录普通字符串,因此我的Regex没有任何匹配项。 我也遵循了几个示例。
Regex101告诉我应该匹配得很好,所以我的C#实现中必须有一些错误。 但我不知道。 我只需要有人让我挺直。 谢谢!
删除正则表达式中的正斜杠。 它们用于指示某些语言或格式的正则表达式的开始和结束,而通过Regex
类创建正则表达式时则不需要。
Regex regex = new Regex("\"(.+)\"");
结果:
“ BOB”
字符串:“ BOB”,匹配值:BOB
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.