获取报价之间的值 [英] Getting values between quotes
本文介绍了获取报价之间的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我怎样才能得到引号之间的值用正则表达式
How can I get the value between quotes with an RegEx
例如我想找到从功能测试
for example I want to find all the parameters from the function test
<html>
test("bla");
print("foo");
test("moo");
</html>
的结果必须是{喇嘛,哞哞}
The result must be { "bla", "moo" }
推荐答案
如果您只想args设置为测试
,你需要包括在正则表达式:
If you just want the args to test
, you'll need to include that in the regex:
StringBuilder sb = new StringBuilder("{");
bool first = true;
foreach (Match match in Regex.Matches(html, @"test\((""[^\""]*\"")\)"))
{
if(first) {first = false;}
else {sb.Append(',');}
sb.Append(match.Groups[1].Value);
}
sb.Append('}');
Console.WriteLine(sb);
这问题,我使用的报价检测在这里。
From the question, I am using quote detection here.
另外 - 如果你只想值:
Alternatively - if you just want the values:
foreach (Match match in Regex.Matches(html, @"test\(""([^\""]*)\""\)"))
{
Console.WriteLine(match.Groups[1].Value);
}
这里的主要变化是,该集团现在是引号内。
The main change here is that the group is now inside the quotes.
这篇关于获取报价之间的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文