使用正则表达式删除两个字符串之间的所有内容 [英] Remove all content between two strings using regular expressions

查看:69
本文介绍了使用正则表达式删除两个字符串之间的所有内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 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.

这篇关于使用正则表达式删除两个字符串之间的所有内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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