regex

package
v0.1.0-dev.20260828173311 Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package regex provides regular expression operations for the operation graph.

Index

Constants

View Source
const (
	Find            op.ActionName = "regex.find"
	FindAll         op.ActionName = "regex.find_all"
	FindAllSubmatch op.ActionName = "regex.find_all_submatch"
	FindSubmatch    op.ActionName = "regex.find_submatch"
	Match           op.ActionName = "regex.match"
	Replace         op.ActionName = "regex.replace"
	ReplaceLiteral  op.ActionName = "regex.replace_literal"
	Split           op.ActionName = "regex.split"
)

Action-name constants for the regex provider's plan-mode actions.

Each constant is the short dotted action label its method dispatches under. Pass these to plan.Plan, op.ReceiverRegistry().BuildAction, RuntimeEnvironment.ActionByName, or WithActionNamed in place of a string literal so a typo is a compile error and rename / find-references work through the constant.

Variables

This section is empty.

Functions

This section is empty.

Types

type Provider

type Provider struct {
	op.ProviderBase
	// contains filtered or unexported fields
}

Provider provides regular expression operations with compiled pattern caching.

func NewProvider

func NewProvider(runtimeEnvironment *op.RuntimeEnvironment) *Provider

NewProvider creates a regex provider bound to the given runtime environment.

func (*Provider) Find

func (p *Provider) Find(pattern, text string) (string, error)

Find returns the first match of the pattern in the text.

Returns an empty string if no match is found.

Parameters:

  • `pattern`: the regular expression pattern.
  • `text`: the string to search.

Returns:

  • `string`: the first match, or empty string if none.
  • `error`: non-nil if the pattern is invalid.

+devlore:claim=deterministic

func (*Provider) FindAll

func (p *Provider) FindAll(pattern, text string, count int) ([]string, error)

FindAll returns all non-overlapping matches of the pattern.

The count parameter limits the number of matches; -1 means no limit.

Parameters:

  • `pattern`: the regular expression pattern.
  • `text`: the string to search.
  • `count`: maximum number of matches (-1 for no limit).

Returns:

  • `[]string`: all matches found.
  • `error`: non-nil if the pattern is invalid.

+devlore:claim=deterministic

func (*Provider) FindAllSubmatch

func (p *Provider) FindAllSubmatch(pattern, text string, count int) ([][]string, error)

FindAllSubmatch returns all matches with their submatches.

The count parameter limits the number of matches; -1 means no limit.

Parameters:

  • `pattern`: the regular expression pattern.
  • `text`: the string to search.
  • `count`: maximum number of matches (-1 for no limit).

Returns:

  • `[][]string`: all matches with submatches.
  • `error`: non-nil if the pattern is invalid.

+devlore:claim=deterministic

func (*Provider) FindSubmatch

func (p *Provider) FindSubmatch(pattern, text string) ([]string, error)

FindSubmatch returns the first match and its submatches.

Returns nil if no match is found.

Parameters:

  • `pattern`: the regular expression pattern.
  • `text`: the string to search.

Returns:

  • `[]string`: the match and submatches, or nil if none.
  • `error`: non-nil if the pattern is invalid.

+devlore:claim=deterministic

func (*Provider) Match

func (p *Provider) Match(pattern, text string) (bool, error)

Match reports whether the text contains any match of the pattern.

Parameters:

  • `pattern`: the regular expression pattern.
  • `text`: the string to search.

Returns:

  • `bool`: true if the pattern matches.
  • `error`: non-nil if the pattern is invalid.

+devlore:claim=deterministic

func (*Provider) Replace

func (p *Provider) Replace(pattern, text, replacement string) (string, error)

Replace replaces all matches of the pattern with the replacement string.

The replacement can include $1, $2, etc. for submatch references.

Parameters:

  • `pattern`: the regular expression pattern.
  • `text`: the string to search.
  • `replacement`: the replacement string (supports submatch references).

Returns:

  • `string`: the text with all matches replaced.
  • `error`: non-nil if the pattern is invalid.

+devlore:claim=deterministic

func (*Provider) ReplaceLiteral

func (p *Provider) ReplaceLiteral(pattern, text, replacement string) (string, error)

ReplaceLiteral replaces all matches with the literal replacement string (no submatch expansion).

Parameters:

  • `pattern`: the regular expression pattern.
  • `text`: the string to search.
  • `replacement`: the literal replacement string.

Returns:

  • `string`: the text with all matches replaced literally.
  • `error`: non-nil if the pattern is invalid.

+devlore:claim=deterministic

func (*Provider) Split

func (p *Provider) Split(pattern, text string, count int) ([]string, error)

Split splits the text around matches of the pattern.

The count parameter limits the number of substrings; -1 means no limit.

Parameters:

  • `pattern`: the regular expression pattern.
  • `text`: the string to split.
  • `count`: maximum number of substrings (-1 for no limit).

Returns:

  • `[]string`: the substrings between matches.
  • `error`: non-nil if the pattern is invalid.

+devlore:claim=deterministic

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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