Golang regexp.Compile() function and FindString() example

package regexp

Golang regexp.Compile() function and FindString() usage example.

 package main

 import (
  "fmt"
  "regexp"
 )

 func main() {

  // regular expression pattern
  re, err := regexp.Compile("a(|b)")

  if err != nil {
 fmt.Println(err)
  }

  s := re.FindString("ab")

  fmt.Println("First match : ", s)

 }

Output :

First match : a

Advertisement