2016-08-15 9 views
-1

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> 

いくつかの類似したスレッドと問題があり、これらのどれもがこの問題のために特にうまく(あるいは全く)働いているようには見えません。

ご協力いただければ幸いです。

+0

'()[\ S \ s] *?()'を検索すると、 '$ 1 $ 2'を置き換えますか? – sln

+0

メモ帳++では、XSLT変換を使用してXMLを簡単に変更できます。 Sublime TextがXSLTによるXMLファイルの変更をサポートしているかどうかは不明です。 –

+0

実際、@WiktorStribiżewが述べているように、これはXSLTで恒等変換を実行し、 ''要素を書き換えることで簡単に処理できます。また、[X/HTMLドキュメント](http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags)でregexを使用しないことを強くお勧めします。 – Parfait

答えて

3

崇高な窓と画像:

Sublime Regex

あなたはを経て、その後を探すを交換し、あなたが最も外側の左のオプションをチェックしてくださいそれを見つけることができます。

1

サブライムあなたはクールなトリックPCREの提供(主に負の先読み)を使用することができなければならないことを意味this page.

によると、PCREを使用するように表示されます。これにより、パフォーマンスが大幅に向上します。

私はお勧め正規表現は次のとおりです。基本的に

<VisibleObject>(?:[^<]*(?!</VisibleObject).)+</VisibleObject> 

、負の先読みは<は(つまり、タグの開始時に)存在している時はいつでも、それはクロージング</VisibleObject>ないことを保証します。

.は、ネガティブ先読みで終了タグが表示されたときにエンジンが1文字をバックトラックできるようにするために必要です。

交換品<VisibleObject></VisibleObject>を使用する必要があります。

関連する問題