Documentation
¶
Overview ¶
Package regexp provides regular expression operations for the operation graph.
Index ¶
- 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 ¶
This section is empty.
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 (*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.