package main
import (
"regexp"
"fmt"
)
func main() {
var re = regexp.MustCompile(`(?m)^(\/.*)\n(.+)\n*|(?<=^(\/.*)\n(?:.+\n)*)(.+)\n*`)
var 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
よろしくお願いします`
var substitution = "$2$4^=$1$3/$2$4\n"
fmt.Println(re.ReplaceAllString(str, substitution))
}
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 Golang, please visit: https://golang.org/pkg/regexp/