使用正则表达式删除两个字符串之间的所有内容

编程入门 行业动态 更新时间:2024-10-23 10:20:08
本文介绍了使用正则表达式删除两个字符串之间的所有内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试在 sublime 3 中使用正则表达式,以删除 两个字符串之间的所有内容,一个 XML 文件.

I am trying to use regular expressions in sublime 3, to remove all the content between two strings, an XML file.

假设这是我的内容:

<Body name="ground"> <mass>0</mass> <mass_center> 0 0 0</mass_center> <inertia_xx>0</inertia_xx> <inertia_yy>0</inertia_yy> <inertia_zz>0</inertia_zz> <inertia_xy>0</inertia_xy> <inertia_xz>0</inertia_xz> <inertia_yz>0</inertia_yz> <!--Joint that connects this body with the parent body.--> <Joint /> <VisibleObject> <!--Set of geometry files and associated attributes, allow .vtp, .stl, .obj--> <GeometrySet> <objects /> <groups /> </GeometrySet> <!--Three scale factors for display purposes: scaleX scaleY scaleZ--> <scale_factors> 1 1 1</scale_factors> <!--transform relative to owner specified as 3 rotations (rad) followed by 3 translations rX rY rZ tx ty tz--> <transform> -0 0 -0 0 0 0</transform> <!--Whether to show a coordinate frame--> <show_axes>false</show_axes> <!--Display Pref. 0:Hide 1:Wire 3:Flat 4:Shaded Can be overriden for individual geometries--> <display_preference>4</display_preference> </VisibleObject> <WrapObjectSet> <objects /> <groups /> </WrapObjectSet> </Body>

现在假设我想删除 和 之间的所有内容,只留下:

Now suppose I want to remove all the content between <VisibleObject> and </VisibleObject> to leave only:

<Body name="ground"> <mass>0</mass> <mass_center> 0 0 0</mass_center> <inertia_xx>0</inertia_xx> <inertia_yy>0</inertia_yy> <inertia_zz>0</inertia_zz> <inertia_xy>0</inertia_xy> <inertia_xz>0</inertia_xz> <inertia_yz>0</inertia_yz> <!--Joint that connects this body with the parent body.--> <Joint /> <VisibleObject> </VisibleObject> <WrapObjectSet> <objects /> <groups /> </WrapObjectSet> </Body>

有一些与上述类似的线程和问题,但似乎没有一个对这个问题特别有效(或根本没有).

There are a few similar threads and problems, to the above but none of them seem to work particularly well (or at all) for this problem.

任何帮助将不胜感激.

推荐答案

带有 sublime 窗口的图像:

An image with the sublime window:

您可以通过查找找到它,然后替换并确保勾选最左边的选项.

You can find it via Find, then Replace and make sure you tick the most outer left options.

更多推荐

使用正则表达式删除两个字符串之间的所有内容

本文发布于:2023-10-23 13:51:21,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1521007.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字符串   所有内容   两个   正则表达式

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!