Notepad++ 行の反転/並べ替え

Notepad++ 行の反転/並べ替え

簡略化された次のコード ブロックのインスタンスが多数あります。

$image = '';
$name = '';
$link = '';
$role_suffix = '';
$role_name = '';
$notes = '';

これらの変数にはすべて異なるデータが含まれています。ファイルを配列に変換する必要があります。これは簡単な検索と置換で実行できますが、まず と切り替える必要があります$link$imageつまり、

$link = '';
$name = '';
$image = '';
$role_suffix = '';
$role_name = '';
$notes = '';

すべてを手動で変更する手間を省くための正規表現ソリューションが必ずあるはずです。さまざまな質問にある回答をまとめてハッキングしてみましたが、正規表現はまったく意味をなさないのです。これを試して(<div>.*?</div>)(\s+)(<span>.*?</span>)、 に置き換えてみました\3\2\1が、正しい構文がよくわかりません。

答え1

  • Ctrl+H
  • 検索対象:(\$image\h*=\h*.+?;)([\s\S]+?)(\$link\h*=\h*.+?;)
  • と置換する:$3$2$1
  • チェック ラップアラウンド
  • 正規表現をチェック
  • チェックを外す. matches newline
  • Replace all

説明:

(               # start group 1
    \$image     # literally
    \h*         # 0 or more horizontal spaces
    =           # equal sign
    \h*         # 0 or more horizontal spaces
    .+?         # 1 or more any character but newline, not greedy
    ;           # semicolon
)               # end group 1
(               # start group 2
    [\s\S]+?    # 1 or more any character, not greedy
)               # end group 2
(               # start group 3
    \$link      # literally
    \h*         # 0 or more horizontal spaces
    =           # equal sign
    \h*         # 0 or more horizontal spaces
    .+?         # 1 or more any character but newline, not greedy
    ;           # semicolon
)               # end group 3

画面キャプチャ:

ここに画像の説明を入力してください

関連情報