0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

サクラエディタ:JavaScriptでマクロ実装(置換編)複数行を一行毎に置換する

Posted at

##複数行を置換するマクロになります。
####下記サンプルコードは、選択されている部分に対して、一行毎に『あ』で始まり『お』で終わる行を置換します。

replace.js
function sakuraReplace(str00) {
 var i=0;
 var lines="";
 var str01="";
 
 lines = str00.split(/(\r|\n|\r\n)/); // 改行コードで分割して変数に代入
 
 for (i in lines) // 分割したライン数をループ
 {
    // 『あ』で始まり『お』で終わる行を置換します。
    str01 +=  lines[i].replace(/^あ.*お$/,'【選択されていた文字を置換しました。】',6) + "\r\n";
 }
 return(str01);
}

var str00 = Editor.GetSelectedString(0); // 選択部分を変数に代入
if ( str00 !== "" ) Editor.InsText(sakuraReplace(str00));
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?