pattern

package
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 14, 2025 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BasicPatternGroup

type BasicPatternGroup interface {
	Match(input string, strict bool) bool
	Extract(input string) string
	ExtractAll(input string) []string
}

BasicPatternGroup defines behavior for matching patterns and extracting substrings from input strings. Match checks if the input string satisfies the pattern, with an option for strict matching. Extract retrieves the first substring from the input string that matches the defined pattern. ExtractAll retrieves all substrings from the input string that match the defined pattern. Should be implemented as a struct containing strict, lenient, and extract patterns Example:

 type EmailPatternGroup struct {
	strictPattern *regexp.Regexp
	lenientPattern *regexp.Regexp
	extractPattern *regexp.Regexp
	}

type ComplexPatternGroup

type ComplexPatternGroup interface {
	Match(input string, name string) (bool, error)
	Extract(input string, name string) (string, error)
	ExtractAll(input string, name string) ([]string, error)
}

ComplexPatternGroup defines an interface for managing and processing groups of complex string patterns. Match checks if the input string matches a custom pattern identified by its name in the provided pattern set. Extract returns the first substring from the input matching a custom pattern specified by its name in the pattern set. ExtractAll returns all substrings from the input matching a custom pattern specified by its name in the pattern set. Should be implemented as a struct containing a custom pattern set. Example:

 type PostalCodePatternGroup struct {
	postalCodeSet *CustomPatternSet
	}

type CustomPatternSet

type CustomPatternSet map[string]*regexp.Regexp

CustomPatternSet is a type that maps string keys to compiled regular expressions. it's strongly recommended to compile regex patterns once and use throughout the application.

func NewCustomPatternSet

func NewCustomPatternSet() CustomPatternSet

NewCustomPatternSet initializes and returns an empty CustomPatternSet for storing named regex patterns.

func (CustomPatternSet) Add

func (cps CustomPatternSet) Add(name string, pattern *regexp.Regexp)

Add adds a new pattern to the CustomPatternSet with the given name as the key and pattern as its value.

func (CustomPatternSet) Exists

func (cps CustomPatternSet) Exists(name string) bool

Exists checks if a pattern with the given name exists in the CustomPatternSet and returns true if found, otherwise false.

func (CustomPatternSet) Get

func (cps CustomPatternSet) Get(name string) (*regexp.Regexp, error)

Get retrieves a compiled regular expression associated with the provided name. Returns an error if the name is not found.

func (CustomPatternSet) GetNames

func (cps CustomPatternSet) GetNames() []string

GetNames returns a slice of all keys (names) present in the CustomPatternSet.

func (CustomPatternSet) Remove

func (cps CustomPatternSet) Remove(name string)

Remove deletes the pattern associated with the given name from the CustomPatternSet.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL