Documentation ¶
Index ¶
- type RegexpRegistry
- func (rr *RegexpRegistry) LinkHandler(fh sprout.Handler) error
- func (rr *RegexpRegistry) RegexFind(regex string, str string) (string, error)
- func (rr *RegexpRegistry) RegexFindAll(regex string, str string, n int) ([]string, error)
- func (rr *RegexpRegistry) RegexMatch(regex string, str string) (bool, error)
- func (rr *RegexpRegistry) RegexQuoteMeta(str string) string
- func (rr *RegexpRegistry) RegexReplaceAll(regex string, str string, replacedBy string) (string, error)
- func (rr *RegexpRegistry) RegexReplaceAllLiteral(regex string, s string, replacedBy string) (string, error)
- func (rr *RegexpRegistry) RegexSplit(regex string, str string, n int) ([]string, error)
- func (rr *RegexpRegistry) RegisterAliases(aliasesMap sprout.FunctionAliasMap) error
- func (rr *RegexpRegistry) RegisterFunctions(funcsMap sprout.FunctionMap) error
- func (rr *RegexpRegistry) RegisterNotices(notices *[]sprout.FunctionNotice) error
- func (rr *RegexpRegistry) Uid() string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type RegexpRegistry ¶
type RegexpRegistry struct {
// contains filtered or unexported fields
}
func NewRegistry ¶
func NewRegistry() *RegexpRegistry
NewRegistry creates a new instance of regexp registry.
func (*RegexpRegistry) LinkHandler ¶
func (rr *RegexpRegistry) LinkHandler(fh sprout.Handler) error
LinkHandler links the handler to the registry at runtime.
func (*RegexpRegistry) RegexFind ¶
func (rr *RegexpRegistry) RegexFind(regex string, str string) (string, error)
RegexFind searches for the first match of a regex pattern in a string and returns it, with error handling.
Parameters:
regex string - the regular expression to search with. str string - the string to search within.
Returns:
string - the first regex match found. error - error if the regex fails to compile.
Example:
{{ "hello world" | RegexFind "hello" }} // Output: "hello", nil
func (*RegexpRegistry) RegexFindAll ¶
RegexFindAll finds all matches of a regex pattern in a string up to a specified limit, with error handling.
Parameters:
regex string - the regular expression to search with. str string - the string to search within. n int - the maximum number of matches to return; use -1 for no limit.
Returns:
[]string - all regex matches found. error - error if the regex fails to compile.
Example:
{{ RegexFindAll "a.", "aba acada afa", 3 }} // Output: ["ab", "ac", "af"], nil
func (*RegexpRegistry) RegexMatch ¶
func (rr *RegexpRegistry) RegexMatch(regex string, str string) (bool, error)
RegexMatch checks if a string matches a regex pattern, with error handling.
Parameters:
regex string - the regular expression to match against. str string - the string to check.
Returns:
bool - true if the string matches the regex pattern, otherwise false. error - error if the regex fails to compile.
Example:
{{ RegexMatch "^[a-zA-Z]+$", "Hello" }} // Output: true, nil
func (*RegexpRegistry) RegexQuoteMeta ¶
func (rr *RegexpRegistry) RegexQuoteMeta(str string) string
RegexQuoteMeta returns a literal pattern string for the provided string.
Parameters:
s string - the string to be escaped.
Returns:
string - the escaped regex pattern.
Example:
{{ regexQuoteMeta ".+*?^$()[]{}|" }} // Output: "\.\+\*\?\^\$\(\)\[\]\{\}\|"
func (*RegexpRegistry) RegexReplaceAll ¶
func (rr *RegexpRegistry) RegexReplaceAll(regex string, str string, replacedBy string) (string, error)
RegexReplaceAll replaces all occurrences of a regex pattern in a string with a replacement string, with error handling.
Parameters:
regex string - the regular expression to replace. str string - the string containing the original text. replacedBy string - the replacement text.
Returns:
string - the modified string after all replacements. error - error if the regex fails to compile.
Example:
{{ RegexReplaceAll "\\d", "R2D2 C3PO", "X" }} // Output: "RXDX CXPO", nil
func (*RegexpRegistry) RegexReplaceAllLiteral ¶
func (rr *RegexpRegistry) RegexReplaceAllLiteral(regex string, s string, replacedBy string) (string, error)
RegexReplaceAllLiteral replaces all occurrences of a regex pattern in a string with a literal replacement string, with error handling.
Parameters:
regex string - the regular expression to replace. s string - the string containing the original text. replacedBy string - the literal replacement text.
Returns:
string - the modified string after all replacements, treating the replacement text as literal text. error - error if the regex fails to compile.
Example:
{{ RegexReplaceAllLiteral "world", "hello world", "$1" }} // Output: "hello $1", nil
func (*RegexpRegistry) RegexSplit ¶
RegexSplit splits a string by a regex pattern up to a specified number of substrings, with error handling.
Parameters:
regex string - the regular expression to split by. str string - the string to split. n int - the maximum number of substrings to return; use -1 for no limit.
Returns:
[]string - the substrings resulting from the split. error - error if the regex fails to compile.
Example:
{{ RegexSplit "\\s+", "hello world from Go", 2 }} // Output: ["hello", "world from Go"], nil
func (*RegexpRegistry) RegisterAliases ¶ added in v0.6.0
func (rr *RegexpRegistry) RegisterAliases(aliasesMap sprout.FunctionAliasMap) error
func (*RegexpRegistry) RegisterFunctions ¶
func (rr *RegexpRegistry) RegisterFunctions(funcsMap sprout.FunctionMap) error
RegisterFunctions registers all functions of the registry.
func (*RegexpRegistry) RegisterNotices ¶ added in v0.6.0
func (rr *RegexpRegistry) RegisterNotices(notices *[]sprout.FunctionNotice) error
func (*RegexpRegistry) Uid ¶
func (rr *RegexpRegistry) Uid() string
Uid returns the unique identifier of the registry.