我有一个xml文件,它有很多行,如:
<xhtml:link vip="true" href="http://store.vcenter.com/stores/en/product/tigers-midi/100" />
如何仅提取链接- http://store.vcenter.com/stores/en/product/tigers-midi/100
我尝试了http://www\.\.com[^<]+,但是它捕捉到了行尾之前的所有内容--包括引号和关闭的XML标记。
我把这个表达式和egrep连用。
发布于 2018-02-16 17:22:45
不要用regex解析HTML,使用适当的XML/HTML解析器。
检查:使用带有HTML标记的正则表达式您可以使用以下内容之一:
xmllintxmlstarletsaxon-lint文件:
<root>
<xhtml:link vip="true" href="http://store.vcenter.com/stores/en/product/tigers-midi/100" />
</root>使用xmllint的示例:
xmllint --xpath '//*[@vip="true"]/@href' file.xml 2>/dev/null输出:
href="http://store.vcenter.com/stores/en/product/tigers-midi/100"如果您需要一个快速和脏的一次命令,您可以:
egrep -o 'https?://[^"]+' filehttps://stackoverflow.com/questions/48831835
复制相似问题