Golang regexp.ReplaceAll() function example

package regexp

Golang regexp.ReplaceAll() function usage example

 package main

 import (
  "fmt"
  "regexp"
 )

 func main() {

  // regular expression pattern
  regE := regexp.MustCompile("[a-c]*$")

  src := []byte("abcdabc")

  repl := []byte("x")

  newByte := regE.ReplaceAll(src, repl)

  fmt.Println(string(newByte)) // convert []byte to string

 }

Output :

abcdx

SEE ALSO : https://www.socketloop.com/references/golang-bytes-replace-function-example

Reference :

http://golang.org/pkg/regexp/#Regexp.ReplaceAll

Advertisement