const regex = /^(\/.*)\n(.+)\n*|(?<=^(\/.*)\n(?:.+\n)*)(.+)\n*/gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('^(\\\/.*)\\n(.+)\\n*|(?<=^(\\\/.*)\\n(?:.+\\n)*)(.+)\\n*', 'gm')
const str = `こんにちは
質問です
●Regular Expressionの使用環境
普通のテキストファイル
いま Sublime text を使ってますが無料のエディタなら何でも使います
●検索か置換か?
置換
●説明
各パラグラフの1行目を2行目以下の全ての行に加えたい
1行目はパラグラフごとに異なり、2行目以下はすべて異なる
●対象データ
/system/app
AntHalService
AutoRegistration
BasicDreams
/system/priv-app
AutoKillService
BackupRestoreConfirmation
●希望する結果
AntHalService^=/system/app/AntHalService
AutoRegistration^=/system/app/AutoRegistration
BasicDreams^=/system/app/BasicDreams
AutoKillService^=/system/priv-app/AutoKillService
BackupRestoreConfirmation^=/system/priv-app/BackupRestoreConfirmation
よろしくお願いします`;
const subst = `$2$4^=$1$3/$2$4\n`;
// The substituted value will be contained in the result variable
const result = str.replace(regex, subst);
console.log('Substitution result: ', result);
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for JavaScript, please visit: https://developer.mozilla.org/en/docs/Web/JavaScript/Guide/Regular_Expressions