我有以下文字
var s = "{{http://foo.com:::Foo Inc.}} would like you to visit {{http://foo.com/home:::Our New Home Page}}"
我想使用以下Regex
和MatchEvaluator
var r = new Regex("\\{\\{(.+)\\:\\:\\:(.+)\\}\\}");
public string Convert(Match m) {
var link = m.Groups[0].ToString();
var text = m.Groups[1].ToString();
return "<a href=\"" + link + "\">" + text + "</a>";
}
以便输出为:
var output = r.Replace(s, Convert);
// output = "<a href="http://foo.com">Foo Inc.</a> would like you to visit <a href="http://foo.com/home">Our New Home Page</a>"
它保持匹配整个字符串而不是每组括号。我怎么能让这个做非贪婪的比赛?
我尝试将其包装在()?
中,但这不会产生非贪婪的匹配
答案 0 :(得分:2)