re = /^(\/.*)\n(.+)\n*|(?<=^(\/.*)\n(?:.+\n)*)(.+)\n*/m
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
よろしくお願いします'
subst = '$2$4^=$1$3/$2$4\\n'
result = str.gsub(re, subst)
# Print the result of the substitution
puts 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 Ruby, please visit: http://ruby-doc.org/core-2.2.0/Regexp.html