Golang regex.LiteralPrefix() function example
package regexp
Golang regex.LiteralPrefix() function usage example
package main
import (
"fmt"
"regexp"
)
func main() {
// regular expression pattern
regE := regexp.MustCompile("/oid/([\\d]+)/")
//searchString := "/oid/1/something_else/oid/2/"
//matchSlice := regE.FindString(searchString)
str, complete := regE.LiteralPrefix()
fmt.Println(complete)
fmt.Println(str)
fmt.Println("------------")
// returns the boolean true if the literal string comprises the entire regular expression
regE = regexp.MustCompile("/oid/")
str, complete = regE.LiteralPrefix()
fmt.Println(complete)
fmt.Println(str)
}
Output :
false
/oid/
true
/oid/
Reference :
Advertisement
Something interesting
Tutorials
+5.5k Golang : Stop goroutine without channel
+7.3k Golang : Fixing Gorilla mux http.FileServer() 404 problem
+8.8k Golang : Take screen shot of browser with JQuery example
+14.5k Golang : How to determine if user agent is a mobile device example
+5.4k Unix/Linux : How to archive and compress entire directory ?
+55.3k Golang : Unmarshal JSON from http response
+7.5k Golang : Gorrila set route name and get the current route name
+9k Golang : automatically figure out array length(size) with three dots
+4.5k Java : Generate multiplication table example
+34k Golang : Proper way to set function argument default value