我有一个超市数据库的查询工作量,我需要分析。我有很多查询,它们作为字符串存储在列表中。它们具有以下形式:
SELECT ... FROM ... WHERE Price = '29' AND Quantity = '2';
或
SELECT ... FROM ... WHERE Price = '10'Discount = '5' AND Category = 'Fruit';
现在我希望将List作为输出,其中包含以下项目:
Price = '29'
Quantity = '2'
Price = '10'
Discount = '5'
Category = 'fruit'
来自每个查询。我尝试使用正则表达式' ='作为模式,但我无法弄清楚如何在该角色之前和之后提取整个单词。
答案 0 :(得分:-1)
你去吧
string input = "SELECT ... FROM ... WHERE Price = '10' AND Discount = '5' AND Category = 'Fruit';";
List<string> result = Regex.Matches(input, @"\w+ = '\w+'")
.Cast<Match>()
.Select(x => x.Value)
.ToList();