【发布时间】:2014-03-24 14:24:00
【问题描述】:
我在查找正则表达式时遇到问题。我有一些文本,可能被一些 xml 分割。例如:
<root>
<text>Thi</text>
<text>s is ju</text>
<text><bold>s</bold></text>
<text>t a tes</text>
<text><italic>t</italic></text>
</root>
我想在xml中搜索“just”这个词,需要结果
ju</text>
<text><bold>s</bold></text>
<text>t
有没有可能用正则表达式得到这个结果?
顺便说一句:我已经有了从 xml 中获取纯文本的正则表达式,它是(在 C#-Syntax 中):
string plaintext = new Regex(@"\<[^\<]*\>").Replace(xmlstring, string.Empty);
这会找到每个“”之间的所有内容(*),但没有找到另一个“
有人有想法吗?
【问题讨论】:
-
不要为此使用正则表达式;它们不适合解析 XML。改用真正的 XML 解析器,这就是它们的用途。