C# 维基百科信息盒解析器
我正在将正则表达式转换为c#,但我仍然坚持将正则表达式转换为c#,我在c#中得到的结果与在JS中得到的结果不同 就是这些C# 维基百科信息盒解析器,c#,regex,wiki,C#,Regex,Wiki,我正在将正则表达式转换为c#,但我仍然坚持将正则表达式转换为c#,我在c#中得到的结果与在JS中得到的结果不同 就是这些 var lists = text.match(/\{\{(order|bulleted|unbulleted|Pagelist)(.*\n)*?\}\}/g); 我试过这个 var matches = text.Matches(@"(\{{(plainlist|order|bulleted|unbulleted|Pagelist)(?:\{??[^\{]*?\}}))");
var lists = text.match(/\{\{(order|bulleted|unbulleted|Pagelist)(.*\n)*?\}\}/g);
我试过这个
var matches = text.Matches(@"(\{{(plainlist|order|bulleted|unbulleted|Pagelist)(?:\{??[^\{]*?\}}))");
但它似乎并不包括所有的比赛
编辑:
使用自定义扩展名:
private static MatchCollection Matches(this string self, string expr)
{
return Regex.Matches(self, expr, System.Text.RegularExpressions.RegexOptions.IgnoreCase);
}
在C#code中,text
似乎是一个没有匹配方法的字符串。您需要使用并且实际上相同的正则表达式也可以工作:
var matches = Regex.Matches(text, @"{{(order|bulleted|unbulleted|Pagelist)(.*\n)*?}}")
.Cast<Match>()
.Select(m => m.Value)
.ToList();
var matches=Regex.matches(文本,@{(顺序|带项目符号|未带项目符号|页面列表)(.*\n)*?})
.Cast()
.选择(m=>m.Value)
.ToList();
如果不需要这两个组中捕获的值,请使用非捕获组((?:…)
)或使用。为什么不使用var matches=Regex.matches(text,@“{(order | bulleted | unbulleted | Pagelist)(.\n)*?}”)
?似乎(.*\n)*?
实际上应该变成(?s:.*?