好日子維奇
這可能不是你要找的解決方案,但它一定會提供許多幫助之一。
我會用這個正則表達式來提取所有標籤
(<\/[a-z]*>)+(<[a-z]*>)+|(<[a-z]*>)+(<\/[a-z]*>)+|(<[a-z]*>)+|(<\/[a-z]*>)+
例子:
string input = "<tr><td>abc</td><td>1</td><td>def</td></tr><tr><td>aaa</td><td>2</td><td>bbb</td></tr>";
string replacement = "#";
string pattern = "(<\/[a-z]*>)+(<[a-z]*>)+|(<[a-z]*>)+(<\/[a-z]*>)+|(<[a-z]*>)+|(<\/[a-z]*>)+";
RegexOptions options = RegexOptions.IgnoreCase | RegexOptions.Compiled |
RegexOptions.Multiline;
Regex rgx = new Regex(pattern, options);
string result = rgx.Replace(input, replacement);
// result == "#abc#1#def#aaa#2#bbb#"
這正則表達式將抓住的標籤,團體或個人,然後你可以用更換分隔符行管道「|」或「#」並在其上分開。 我希望這可以幫助。
親切的問候
Ps。正則表達式解釋: 管道用作或運營商
(<\/[a-z]*>)+(<[a-z]*>)+ // Closing tag(s) that are followed by opening tag(s)
(<[a-z]*>)+(<\/[a-z]*>)+ // Opening tags followed by closing tags
(<[a-z]*>)+ // one or more opening tags
(<\/[a-z]*>)+ // one or more closing tags
有效的XML文檔必須具有單個根節點。轉換前將字符串包裝在一個字符串中。 –
因爲在該串具有一定的符號
你能給我所有的字符串嗎? –