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 :
Advertisement
Something interesting
Tutorials
+8.3k Golang : Check if integer is power of four example
+6.1k Golang : Missing Subversion command
+11k Golang : Replace a parameter's value inside a configuration file example
+33.9k Golang : Call a function after some delay(time.Sleep and Tick)
+9.1k Golang : Handle sub domain with Gin
+5.3k Javascript : Shuffle or randomize array example
+15.9k Golang : Update database with GORM example
+36.5k Golang : Validate IP address
+44.9k Golang : Use wildcard patterns with filepath.Glob() example
+35.5k Golang : Smarter Error Handling with strings.Contains()
+15k Golang : package is not in GOROOT during compilation
+7.1k Golang : Squaring elements in array