事实是,我有一个很难写的正则表达式的字符串进行解析东西的正则表达式中的正则表达式?
[[[tab name=dog content=cat|tab name=dog2 content=cat2]]]
此正则表达式的形式将被解析,这样我可以动态地构建标签为这里展示。最初我尝试了一个像\[\[\[tab name=(?'name'.*?) content=(?'content'.*?)\]\]\]
正则表达式模式但我意识到我无法得到整个选项卡,并建立在查询没有做regex.replace。是否有可能将整个选项卡作为一个组采用管道符号,然后从子键/值对中解析该组?
这是当前正则表达式字符串我与\[\[\[(?'tab'tab name=(?'name'.*?) content=(?'content'.*?))\]\]\]
工作,这是我的执行正则表达式的代码。任何指导将不胜感激。
public override string BeforeParse(string markupText)
{
if (CompiledRegex.IsMatch(markupText))
{
// Replaces the [[[code lang=sql|xxx]]]
// with the HTML tags (surrounded with {{{roadkillinternal}}.
// As the code is HTML encoded, it doesn't get butchered by the HTML cleaner.
MatchCollection matches = CompiledRegex.Matches(markupText);
foreach (Match match in matches)
{
string tabname = match.Groups["name"].Value;
string tabcontent = HttpUtility.HtmlEncode(match.Groups["content"].Value);
markupText = markupText.Replace(match.Groups["content"].Value, tabcontent);
markupText = Regex.Replace(markupText, RegexString, ReplacementPattern, CompiledRegex.Options);
}
}
return markupText;
}
你的真实世界中有更多的数据,你的例子没有提供足够的复杂性吗? – OmegaMan