Documentation
¶
Overview ¶
Package regex provides regular expression operations for the operation graph.
Index ¶
- Constants
- type Provider
- func (p *Provider) Find(pattern, text string) (string, error)
- func (p *Provider) FindAll(pattern, text string, count int) ([]string, error)
- func (p *Provider) FindAllSubmatch(pattern, text string, count int) ([][]string, error)
- func (p *Provider) FindSubmatch(pattern, text string) ([]string, error)
- func (p *Provider) Match(pattern, text string) (bool, error)
- func (p *Provider) Replace(pattern, text, replacement string) (string, error)
- func (p *Provider) ReplaceLiteral(pattern, text, replacement string) (string, error)
- func (p *Provider) Split(pattern, text string, count int) ([]string, error)
Constants ¶
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.
+devlore:access=both
func NewProvider ¶
func NewProvider(runtimeEnvironment *op.RuntimeEnvironment) *Provider
NewProvider creates a regex provider bound to the given runtime environment.
func (*Provider) Find ¶
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.
func (*Provider) FindAll ¶
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.
func (*Provider) FindAllSubmatch ¶
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.
func (*Provider) FindSubmatch ¶
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.
func (*Provider) Match ¶
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.
func (*Provider) Replace ¶
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.
func (*Provider) ReplaceLiteral ¶
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.
func (*Provider) Split ¶
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.