Documentation
¶
Index ¶
- Constants
- func All(re *regexp2.Regexp, s string) iter.Seq[*regexp2.Match]
- func Compile(pattern string, opts ...Option) (*regexp2.Regexp, error)
- func Find(re *regexp2.Regexp, s string) *regexp2.Match
- func Group(m *regexp2.Match, n int) string
- func Lazy[T any](compile func(string) T, pattern string) func() T
- func Match(re *regexp2.Regexp, s string) bool
- func MustCompile(pattern string) *regexp2.Regexp
- func NamedGroup(m *regexp2.Match, name string) string
- func Replace(re *regexp2.Regexp, s, template string) string
- func ReplaceFunc(re *regexp2.Regexp, s string, fn func(regexp2.Match) string) string
- func ReplaceSubmatchFunc(re *regexp.Regexp, s string, fn func(groups []string) string) string
- type Error
- type Option
Constants ¶
const DefaultTimeout = 2 * time.Second
Longest one match of a pattern from Compile may run before it gives up, the guard against catastrophic backtracking
Variables ¶
This section is empty.
Functions ¶
func All ¶
Successive non-overlapping matches of re in s from left to right, ending early and silently when a match runs out of time, which only a Compile pattern can do
func Compile ¶
Pattern from outside the program (a user, a config file, a skill, a plugin, the model) compiled in the package dialect: \w \d \s \b and case folding Unicode-aware, $ also before a final line break, (?P<name>...) (?P=name) \Z {,n} possessive quantifiers \x{...} \N{NAME} and the a flag read as the patterns already written expect, plus lookaround, backreferences, atomic groups and conditionals; groups are numbered left to right and every match gives up after DefaultTimeout with an error whose text quotes the whole subject
func Find ¶
Leftmost match of re in s, nil when there is none or the match runs out of time, which only a Compile pattern can do
func Group ¶
Text of group n of m, empty when m is nil, the group does not exist or it took no part in the match
func Lazy ¶
Function that compiles pattern with compile on its first call and hands back that same value on every later call, safe for concurrent first use, keeping package level patterns out of program start-up; a compile that panics panics again with the same value on every call
func Match ¶
Whether re matches somewhere in s, false when the match runs out of time, which only a Compile pattern can do: a decision that must not read a give-up as no match calls re.MatchString and handles its error
func MustCompile ¶
Pattern written in the program compiled in the dialect Compile takes but without a time limit, panicking with an *Error when it does not compile
func NamedGroup ¶
Text of the group called name in m, empty when m is nil, the pattern has no such group or it took no part in the match
func Replace ¶
s with every match of re replaced by template, in which $1 or ${1}, ${name}, $0 and $$ stand for a group, a named group, the whole match and a dollar sign, a reference to a group the pattern lacks staying literal text and a group that took no part giving nothing; s unchanged when the template is malformed or a match runs out of time, which only a Compile pattern can do
func ReplaceFunc ¶
s with every match of re replaced by what fn returns for it, s unchanged when a match runs out of time, which only a Compile pattern can do