a■ああ■いい……
b■うう■ええ……
c■おお■かか……
というデータをマクロで
a
aああ
aいい……
b
bうう
bええ……
c
cおお
cかか……
に変換したいのですが、区切りの「■」の数は不定で、「a」や「ああ」などの長さも不定です。
ご教示、よろしくお願いいたします。
スタック・オーバーフローはプログラマーとプログラミングに熱心な人のためのQ&Aサイトです。すぐ登録できます。
登録してこのコミュニティに参加するre1 = editor.regex;
re1.Engine = eeExFindRegexOnigmo;
re1.Pattern = "^(.*?)(■.*)$";
for( var yLine = document.GetLines(); yLine > 0; yLine-- ){
line = document.GetLine( yLine , eeGetLineWithNewLines );
m = re1.Find( line );
if( ! m ) continue;
tag = m.Item(1).Value;
str = m.Item(2).Value;
re2 = editor.regex;
re2.Engine = eeExFindRegexOnigmo;
re2.Pattern = "■+([~■]*)";
re2.Global = true;
str = re2.Replace( str, "\n" + tag + "\\1" );
document.selection.SetActivePoint( eePosLogical, 1, yLine );
document.selection.SelectLine();
document.selection.Text = tag + str + "\n";
}
split() を使えばもっとシンプルでした
for( var yLine = document.GetLines(); yLine > 0; yLine-- ){
var para = document.GetLine( yLine ).split( /■+/ )
if( para.length <= 1 ) continue;
var tag = para[0];
var str = tag + "\n";
for( var i = 1; i < para.length; i++ ){
str += tag + para[i] + "\n";
}
document.selection.SetActivePoint( eePosLogical, 1, yLine );
document.selection.SelectLine();
document.selection.Text = str;
}