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