Documentation
¶
Overview ¶
Package regexp selects the fastest regex engine available for a pattern.
By default it compiles patterns with coregex (an accelerated RE2-compatible engine). When the pattern requires PCRE/Perl features that RE2/coregex cannot execute, the package automatically falls back to regexp2 for full PCRE2 compatibility.
Index ¶
- func Match(pattern string, b []byte) (bool, error)
- func MatchString(pattern, s string) (bool, error)
- func QuoteMeta(s string) string
- type Regexp
- func (r *Regexp) Find(b []byte) []byte
- func (r *Regexp) FindAll(b []byte, n int) [][]byte
- func (r *Regexp) FindAllIndex(b []byte, n int) [][]int
- func (r *Regexp) FindAllString(s string, n int) []string
- func (r *Regexp) FindAllStringIndex(s string, n int) [][]int
- func (r *Regexp) FindAllStringSubmatch(s string, n int) [][]string
- func (r *Regexp) FindAllStringSubmatchIndex(s string, n int) [][]int
- func (r *Regexp) FindAllSubmatch(b []byte, n int) [][][]byte
- func (r *Regexp) FindAllSubmatchIndex(b []byte, n int) [][]int
- func (r *Regexp) FindIndex(b []byte) []int
- func (r *Regexp) FindString(s string) string
- func (r *Regexp) FindStringIndex(s string) []int
- func (r *Regexp) FindStringSubmatch(s string) []string
- func (r *Regexp) FindStringSubmatchIndex(s string) []int
- func (r *Regexp) FindSubmatch(b []byte) [][]byte
- func (r *Regexp) FindSubmatchIndex(b []byte) []int
- func (r *Regexp) Longest()
- func (r *Regexp) Match(b []byte) bool
- func (r *Regexp) MatchString(s string) bool
- func (r *Regexp) NumSubexp() int
- func (r *Regexp) ReplaceAll(src []byte, repl []byte) []byte
- func (r *Regexp) ReplaceAllString(src, repl string) string
- func (r *Regexp) Split(s string, n int) []string
- func (r *Regexp) String() string
- func (r *Regexp) SubexpNames() []string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Match ¶
Match reports whether the byte slice b matches the regular expression pattern. This mirrors regexp.Match.
func MatchString ¶
MatchString reports whether the string s matches the regular expression pattern. This mirrors regexp.MatchString.
Types ¶
type Regexp ¶
type Regexp struct {
// contains filtered or unexported fields
}
Regexp is a compiled regular expression that delegates to either coregex (fast, RE2-compatible) or regexp2 (PCRE-compatible) depending on the pattern features detected at compile time.
func Compile ¶
Compile parses a regular expression and returns a compiled Regexp. Patterns that require PCRE/Perl-only features (detected by needsPCRE) are compiled with regexp2; everything else uses coregex for speed.
func MustCompile ¶
MustCompile is like Compile but panics if the expression cannot be parsed.
func (*Regexp) Find ¶
Find returns the leftmost match of the Regexp in b.
func (*Regexp) FindAll ¶
FindAll returns a slice of all successive matches of the Regexp in b.
func (*Regexp) FindAllIndex ¶
FindAllIndex returns a slice of all successive match indices of the Regexp in b.
func (*Regexp) FindAllString ¶
FindAllString returns a slice of all successive matches of the Regexp in s.
func (*Regexp) FindAllStringIndex ¶
FindAllStringIndex returns a slice of all successive match indices of the Regexp in s.
func (*Regexp) FindAllStringSubmatch ¶
FindAllStringSubmatch returns a slice of all successive matches of the Regexp in s and their submatches.
func (*Regexp) FindAllStringSubmatchIndex ¶
FindAllStringSubmatchIndex returns a slice of all successive match index pairs of the Regexp in s and their submatches.
func (*Regexp) FindAllSubmatch ¶
FindAllSubmatch returns a slice of all successive matches of the Regexp in b and their submatches.
func (*Regexp) FindAllSubmatchIndex ¶
FindAllSubmatchIndex returns a slice of all successive match index pairs of the Regexp in b and their submatches.
func (*Regexp) FindIndex ¶
FindIndex returns a two-element slice with the start and end index of the leftmost match in b.
func (*Regexp) FindString ¶
FindString returns the leftmost match of the Regexp in s.
func (*Regexp) FindStringIndex ¶
FindStringIndex returns a two-element slice with the start and end index of the leftmost match in s.
func (*Regexp) FindStringSubmatch ¶
FindStringSubmatch returns the leftmost match of the Regexp in s and its submatches as strings.
func (*Regexp) FindStringSubmatchIndex ¶
FindStringSubmatchIndex returns the index pairs identifying the leftmost match of the Regexp in s and its submatches.
func (*Regexp) FindSubmatch ¶
FindSubmatch returns slices identifying the leftmost match of the Regexp in b and its submatches.
func (*Regexp) FindSubmatchIndex ¶
FindSubmatchIndex returns slices holding the index pairs identifying the leftmost match of the Regexp in b and its submatches.
func (*Regexp) Longest ¶
func (r *Regexp) Longest()
Longest switches the underlying engine to leftmost-longest matching when supported. coregex provides this directly; regexp2 is already PCRE-style and does not change behavior here.
func (*Regexp) Match ¶
Match reports whether the byte slice b contains any match of the Regexp.
func (*Regexp) MatchString ¶
MatchString reports whether the string s contains any match of the Regexp.
func (*Regexp) NumSubexp ¶
NumSubexp returns the number of parenthesized subexpressions in this Regexp.
func (*Regexp) ReplaceAll ¶
ReplaceAll returns a copy of src, replacing matches of the Regexp with repl.
func (*Regexp) ReplaceAllString ¶
ReplaceAllString returns a copy of src, replacing matches of the Regexp with repl.
func (*Regexp) Split ¶
Split slices s into substrings separated by the Regexp.
func (*Regexp) String ¶
String returns the source pattern used to compile the Regexp.
Source Files
¶
- doc.go
- regexp.go
- utils.go