Notepad ++ で行を置き換えて一部を残す

Notepad ++ で行を置き換えて一部を残す

Notepad++ を使用して、大量のコードを検索/置換したい:

たくさん持っています:

角度[]={6.2744589,5.4066987,1.4066987};

3 つの値があります。最初と 2 番目の値をすべて 0 にして、3 番目の位置の値はそのままにする必要があります :S

角度[]={6.2744589,5.4066987,1.4066987};

角度[]={0,0,1.4066987};

ありがとう!

答え1

これは、Notepad++ の regex (正規表現) 検索と置換で実現できます。

探す:angles\[\]={\d+\.\d+,\d+\.\d+,(\d+\.\d+)};

と置換する:angles[]={0,0,\1}

上記の式では、括弧をエスケープしているため、バックスラッシュ () が存在し、3 番目のグループはキャプチャ グループ (括弧内) であることに注意してください。最後に、最初と 2 番目のグループの置換を実行し、3 番目のグループは元の値 (\1キャプチャされた値と呼ばれる) になります。

スクリーンショットのサンプルを添付します。

Notepad++ 正規表現の置換

答え2

  • Ctrl+H
  • 検索対象:\bangles\[\]=\{\K[^,]+,[^,]+
  • と置換する:0,0
  • Replace all

説明:

\b          : word boundary, to be sure to match angles but not somethingangles
angles      : literally angles
\[\]=\{     : literally []=, brackets have to be escaped as they have special meaning in regex
\K          : Forget all we have seen until this point
[^,]+       : 1 or more any character that is not a comma, that matches also negative values
,           : a comma
[^,]+       : 1 or more any character that is not a comma
  • 正規表現をチェックする
  • チェックしないでください. matches newline

与えられた例の結果:

angles[]={0,0,1.4066987};

関連情報