Golang regexp.MustCompile() function example

package regexp

Golang regexp.MustCompile() function usage example.

 package main

 import (
  "fmt"
  "regexp"
 )

 func main() {

  // regular expression pattern
  regE := regexp.MustCompile("/oid/([\\d]+)/")

  // simulate a search

  // first convert string to byte for Find() function
  searchByte := []byte("/oid/1/")

  matchSlice := regE.Find(searchByte)

  fmt.Printf("%s \n", matchSlice)

 }

References :

https://www.socketloop.com/tutorials/golang-regular-expression-find-string-example

http://golang.org/pkg/regexp/#MustCompile

Advertisement