有一个sql查询语句 select * from User where name=' ' and compary='#$%%$##'
我想查找所有单引号里面的东西,就比如这个name=' '中' ',compary='#$%%$##'中'#$%%$##',单引号里面可能有各种字符串,也有可能是空。
请问这个这个正则表达式怎么写?
我想查找所有单引号里面的东西,就比如这个name=' '中' ',compary='#$%%$##'中'#$%%$##',单引号里面可能有各种字符串,也有可能是空。
请问这个这个正则表达式怎么写?
void Main()
{
string s=@" select * from User where name=' ' and compary='#$%%$##'";
foreach(Match m in Regex.Matches(s,@"(?<==').*?[^'](?=')"))
{
Console.WriteLine(m.Value);
}
}/*
#$%%$##
*/
foreach (Match m in mc)
{
TextBox1.Text += m.Value + "\n";
}
foreach (Match m in mc)
{
TextBox1.Text += m.Value + "\n";
}
foreach (Match m in mc)
{
TextBox1.Text += m.Value + "\n";
}
foreach(Match m in Regex.Matches(s,@"(?<=').*?[^'](?=')"))
{
//m为匹配后的结果可以对匹配的结果操作
}
Dictionary<string, string> condition = new Dictionary<string, string>();
Match m = Regex.Match(sql, @"where(\s*(?:and\s*)?(\S*)\s*=\s*(')?((?:(?!\3).)+)\3)+");
for (int i = 0; i < m.Groups[1].Captures.Count; i++)
{
condition.Add(m.Groups[2].Value, m.Groups[4].Value);
}
condition//就是你要的结果
string sql = "select * from User where name=' ' and compary='#$%%$##' and xxx='abcd''efg'";
foreach (Match m in Regex.Matches(sql, pattern))
{
Console.WriteLine("【{0}】", m.Groups[1].Value);
}