我得到了下面的代码,适用于单引号。它找到单引号之间的所有单词。 但我将如何修改正则表达式使用双引号?Regex.Matches c#双引号
关键字是从表单POST
来得这么
keywords = 'peace "this world" would be "and then" some'
// Match all quoted fields
MatchCollection col = Regex.Matches(keywords, @"'(.*?)'");
// Copy groups to a string[] array
string[] fields = new string[col.Count];
for (int i = 0; i < fields.Length; i++)
{
fields[i] = col[i].Groups[1].Value; // (Index 1 is the first group)
}// Match all quoted fields
MatchCollection col = Regex.Matches(keywords, @"'(.*?)'");
// Copy groups to a string[] array
string[] fields = new string[col.Count];
for (int i = 0; i < fields.Length; i++)
{
fields[i] = col[i].Groups[1].Value; // (Index 1 is the first group)
}
那不是工作,把引号括起来的吗? @字符串使用“”而不是\“作为引号。”@“”“(。*?)”“”' – 2012-02-03 18:01:00