Categories
Regular Expression

Literals in Regular Expression

Literals are the simplest form of pattern matching in regular expressions. They will simply succeed whenever that literal is found.

func Match 

func Match(pattern string, b []byte) (matched bool, err error)

Match reports whether the byte slice b contains any match of the regular expression pattern.

Example Code

package main

import (
	"fmt"
	"regexp"
)

func main() {
        pattern:="Hello"
        // Match() function return a boolean type value 
        // with boolean it limit us from extracting the match string value
	matched, err := regexp.Match(pattern, []byte(`World Hello`))
	// print value return from Match() func
	fmt.Println(matched, err)
	if matched {
	   fmt.Println("Found")
	} else {
	   fmt.Println("Not Found")
	}
}

Go Playground

https://play.golang.org/p/ts3SyaxKQgF

Resources

go doc regexp/syntax

https://pkg.go.dev/regexp?tab=doc#pkg-overview