我有一个有趣的问题,我想找到一个最好的解决方案,我已经尽力与正则表达式。我想要的是使用正则表达式或任何其他方法,使用c从这个字符串中查找所有的col_x
值。
[col_5] is a central heating boiler manufacturer produce boilers under [col_6]
brand name . Your selected [col_7] model name is a [col_6] [col_15] boiler.
[col_6] [col_15] boiler [col_7] model [col_10] came in production untill
[col_11]. [col_6] model product index number is [col_1] given by SEDBUK
'Seasonal Efficiency of a Domestic Boiler in the UK'. [col_6] model have
qualifier [col_8] and GCN [col_9] 'Boiler Gas Council No'. [col_7] model
source of heat for a boiler combustion is a [col_12].
所需的输出是一个数组
var data =["col_5","col_10","etc..."]
编辑
我的尝试:
string text = "[col_1]cc[col_2]asdfsd[col_3]";
var matches = Regex.Matches(text, @"[[^@]*]");
var uniques = matches.Cast<Match>().Select(match => match.Value).ToList().Distinct();
foreach(string m in uniques)
{
Console.WriteLine(m);
}
但没有成功。
最佳答案
试试这样的:
string[] result = Regex.Matches(input, @"\[(col_\d+)\]").
Cast<Match>().
Select(x => x.Groups[1].Value).
ToArray();