package main
import (
"regexp"
"fmt"
)
func main() {
var re = regexp.MustCompile(`(?m)^
([^\|]+?)(?:\|\1)*
(\|(?!\1)[^\|]+?)?(?:\|\1|\2)*
((?!\|\1|\2)\|[^\|]+?)?(?:\|\1|\2|\3)*
((?!\|\1|\2|\3)\|[^\|]+?)?(?:\|\1|\2|\3|\4)*
((?!\|\1|\2|\3|\4)\|[^\|]+?)?(?:\|\1|\2|\3|\4|\5)*
((?!\|\1|\2|\3|\4|\5)\|[^\|]+?)?(?:\|\1|\2|\3|\4|\5|\6)*
$`)
var str = `TPL1
TPL1|TPL1
TPL2
TPL1|TPL2
TPL2|TPL2|TPL1
TPL1|TPL2|TPL1
TPL2|TPL2|TPL2
TPL2|TPL2|TPL2|TPL1|TPL1
TPL2|TPL1|TPL3|TPL2|TPL2|TPL1|TPL1|TPL3|TPL3
TPL1|TPL1|TPL2|TPL2|TPL2|TPL3|TPL3|TPL3|TPL3|TPL1|TPL1
TPL1|TPL1|TPL1|TPL2|TPL2|TPL2|TPL3|TPL3|TPL3|TPL4|TPL4|TPL4|TPL5|TPL5|TPL5|TPL6|TPL6|TPL6
TPL1|TPL6|TPL1|TPL2|TPL2|TPL5|TPL2|TPL3|TPL1|TPL3|TPL4|TPL4|TPL5|TPL3|TPL5|TPL6|TPL4|TPL6`
var substitution = "$1$2$3$4$5$6"
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/