2つの文字列、つまりXMLファイルの間で、昇華型3で正規表現を使用しようとしています。正規表現を使用して2つの文字列間のすべてのコンテンツを削除します。
これは私のコンテンツであると仮定します
<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>
は今、私は唯一のままにする<VisibleObject>
と</VisibleObject>
間のすべてのコンテンツを削除したいとします
<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>
いくつかの類似したスレッドと問題があり、これらのどれもがこの問題のために特にうまく(あるいは全く)働いているようには見えません。
ご協力いただければ幸いです。
'()[\ S \ s] *?( VisibleObject>)'を検索すると、 '$ 1 $ 2'を置き換えますか? –
sln
メモ帳++では、XSLT変換を使用してXMLを簡単に変更できます。 Sublime TextがXSLTによるXMLファイルの変更をサポートしているかどうかは不明です。 –
実際、@WiktorStribiżewが述べているように、これはXSLTで恒等変換を実行し、 ''要素を書き換えることで簡単に処理できます。また、[X/HTMLドキュメント](http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags)でregexを使用しないことを強くお勧めします。 –
Parfait