Golang regexp.Find() function example
package regexp
Golang regexp.Find() function usage example
package main
import (
"fmt"
"regexp"
)
func main() {
// regular expression pattern
regE := regexp.MustCompile("/oid/([\\d]+)/")
// first convert string to byte for Find() function
searchByte := []byte("/somethingelse/oid/32/between/oid/33/")
matchSlice := regE.Find(searchByte)
fmt.Printf("%s \n", matchSlice)// leftmost match oid 33 is not qualified
}
Output :
/oid/32/
References :
http://golang.org/pkg/regexp/#Regexp.Expand
https://www.socketloop.com/tutorials/golang-regular-expression-find-string-example
Advertisement
Something interesting
Tutorials
+12.9k Python : Convert IPv6 address to decimal and back to IPv6
+19.2k Golang : Populate dropdown with html/template example
+16.3k Golang : Find out mime type from bytes in buffer
+19.6k Golang : Get current URL example
+18.8k Golang : Delete duplicate items from a slice/array
+14.9k Golang : How to check for empty array string or string?
+9.7k Golang : Eroding and dilating image with OpenCV example
+9.1k Golang : io.Reader causing panic: runtime error: invalid memory address or nil pointer dereference
+14.8k Golang : Normalize unicode strings for comparison purpose
+10.9k Golang : Removes punctuation or defined delimiter from the user's input
+5k Google : Block or disable caching of your website content
+5.6k PHP : Fix Call to undefined function curl_init() error