Documentation
¶
Overview ¶
Package uregex compiles user-supplied regular expressions for the operations that accept them. It prefers Go's RE2 engine for its linear-time guarantee and falls back to regexp2 in ECMAScript (JavaScript-compatible) mode only when a pattern uses a feature RE2 lacks — lookahead, lookbehind, backreferences, or JavaScript named-group syntax. The regexp2 path is bounded by a match timeout, since it can backtrack.
Both engines are presented through a small Regexp interface that mirrors the two shapes the operations need from the standard library: a list of matches with their capture-group text, and the same with byte offsets.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Regexp ¶
type Regexp interface {
// MatchString reports whether the pattern matches anywhere in s.
MatchString(s string) bool
// ReplaceAll replaces every match with repl, expanding $-group references.
ReplaceAll(src, repl string) string
// ReplaceFirst replaces only the first match with repl.
ReplaceFirst(src, repl string) string
// FindStringSubmatch returns the first match: element 0 is the whole match
// and later elements are the capture groups (empty string if a group did not
// participate). It returns nil when there is no match.
FindStringSubmatch(s string) []string
// FindAllStringSubmatch returns every non-overlapping match. In each result,
// element 0 is the whole match and later elements are the capture groups; a
// group that did not participate is the empty string.
FindAllStringSubmatch(s string) [][]string
// FindAllStringSubmatchIndex returns the same matches as byte-offset pairs:
// [start,end] of the whole match followed by [start,end] of each group, with
// -1,-1 for a group that did not participate.
FindAllStringSubmatchIndex(s string) [][]int
}
Regexp is the behavior the operations need from a compiled user pattern.