Patterns - craterdog/go-component-framework GitHub Wiki

Overview

A pattern string is a sequence of characters that define a regular expression. Each pattern string has the following string format:

$pattern: "none" | REGEX | "any"

The source of this format is Bali Document Notation™ (Bali) defined here.

The none pattern will not match anything whereas the any pattern will match absolutely anything including an empty string "".

UML Diagram

A Quick Example

To whet your appetite, here is some short example code that demonstrates the use of pattern strings.

package main

import (
	fmt "fmt"
	fra "github.com/craterdog/go-component-framework/v7"
)

func main() {
	// Retrieve the class reference.
	var class = fra.PatternClass()

	// Retrieve a class constant.
	var any = class.Any()
	fmt.Println(any)

	// Create a new pattern string.
	var pattern = class.PatternFromString(`"c(.+t)"?`)
	fmt.Println(pattern)

	// Check for pattern matches.
	fmt.Println(pattern.MatchesText("caaat"))
	fmt.Println(any.MatchesText("caaat"))
	fmt.Println(pattern.MatchesText("kat"))
	fmt.Println(any.MatchesText("kat"))
}

Try it out in the Go Playground...