事實是,我有一個很難寫的正則表達式的字符串進行解析東西的正則表達式中的正則表達式?
[[[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