使用RegEx查找两个XML标记之间的所有内容 [英] Find everything between two XML tags with RegEx

查看:95
本文介绍了使用RegEx查找两个XML标记之间的所有内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

RegEx 中,我想找到两个 XML标签之间的标签和所有内容,如下所示:

In RegEx, I want to find the tag and everything between two XML tags, like the following:

<primaryAddress>
    <addressLine>280 Flinders Mall</addressLine>
    <geoCodeGranularity>PROPERTY</geoCodeGranularity>
    <latitude>-19.261365</latitude>
    <longitude>146.815585</longitude>
    <postcode>4810</postcode>
    <state>QLD</state>
    <suburb>Townsville</suburb>
    <type>PHYSICAL</type>
</primaryAddress>

我想在 primaryAddress ,并删除它。

primaryAddress 标签之间的所有内容都是变量,但我想删除整个标签和子标签我得到 primaryAddress

Everything between the primaryAddress tag is a variable, but I want to remove the entire tag and sub-tags whenever I get primaryAddress.

任何人都知道怎么做?

推荐答案

使用正则表达式进行HTML / XML解析不是一个好主意......



但是,无论如何你想要这样做,搜索正则表达式

It is not a good idea to use regex for HTML/XML parsing...

However, if you want to do it anyway, search for regex pattern

<primaryAddress>[\s\S]*?<\/primaryAddress>

并将其替换为空字符串......

and replace it with empty string...

这篇关于使用RegEx查找两个XML标记之间的所有内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆