by shigemk2

当面は技術的なことしか書かない

golang regexp

golang regexp

どちらかといえば括弧書きのほう

package main

import "fmt"
import "regexp"

func main() {
    str := "123456"
    rep := regexp.MustCompile(`1(.)3(.)5(.)`)
    str = rep.ReplaceAllString(str, "1($1)3($2)5($3)")

    fmt.Println(str) // => "1(2)3(4)5(6)"
}

http://ashitani.jp/golangtips/tips_regexp.html