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 :

http://golang.org/pkg/regexp/#Regexp.LiteralPrefix

Advertisement