Golang regexp.QuoteMeta() function examples
package regexp
Golang regexp.QuoteMeta() function usage examples.
Note : Useful in situation where you want to do a strings.Join()
Example 1:
package main
import (
"fmt"
"regexp"
)
func main() {
// regular expression pattern
str := regexp.QuoteMeta("[boo]")
fmt.Println("Meta : ", str)
}
Example 2 :
regexp.MustCompile(`\b(?:` + strings.Join([]string{
`go\s+get\s+`,
`goinstall\s+`,
regexp.QuoteMeta("http://godoc.org/"),
regexp.QuoteMeta("http://gopkgdoc.appspot.com/pkg/"),
regexp.QuoteMeta("http://go.pkgdoc.org/"),
regexp.QuoteMeta("http://gowalker.org/"),
}, "|") + `)([-a-zA-Z0-9~+_./]+)`)
Advertisement
Something interesting
Tutorials
+9.9k Golang : Sort and reverse sort a slice of integers
+5.6k Fix fatal error: evacuation not done in time problem
+8.8k Golang : Random integer with rand.Seed() within a given range
+7.6k Golang : Convert(cast) io.Reader type to string
+15.4k Golang : Find location by IP address and display with Google Map
+12k Golang : Convert a rune to unicode style string \u
+8.7k Golang : Find duplicate files with filepath.Walk
+51.1k Golang : Disable security check for HTTPS(SSL) with bad or expired certificate
+5.9k AWS S3 : Prevent Hotlinking policy
+11.6k Golang : Simple file scaning and remove virus example
+3.4k Golang : Fix go-cron set time not working issue
+30.4k Golang : Generate random string