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

查看:38
本文介绍了使用 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 之间的所有内容,然后删除它.

I want to find the tag and everything between primaryAddress, and erase that.

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>[sS]*?</primaryAddress>

并用空字符串替换它...

and replace it with empty string...

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

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