Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
181 views
in Technique[技术] by (71.8m points)

regex - Remove all content between two strings using regular expressions

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

Suppose this is my content:

        <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.

Any help would be most appreciated.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

An image with the sublime window:

Sublime Regex

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...