regexp

package module
v0.0.0-...-8146954 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 8, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func Match

func Match(pattern string, b []byte) (bool, error)

Match reports whether the byte slice b matches the regular expression pattern. This mirrors regexp.Match.

func MatchString

func MatchString(pattern, s string) (bool, error)

MatchString reports whether the string s matches the regular expression pattern. This mirrors regexp.MatchString.

func QuoteMeta

func QuoteMeta(s string) string

QuoteMeta escapes all regular expression metacharacters in s.

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

func Compile(pattern string) (*Regexp, error)

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

func MustCompile(pattern string) *Regexp

MustCompile is like Compile but panics if the expression cannot be parsed.

func (*Regexp) Find

func (r *Regexp) Find(b []byte) []byte

Find returns the leftmost match of the Regexp in b.

func (*Regexp) FindAll

func (r *Regexp) FindAll(b []byte, n int) [][]byte

FindAll returns a slice of all successive matches of the Regexp in b.

func (*Regexp) FindAllIndex

func (r *Regexp) FindAllIndex(b []byte, n int) [][]int

FindAllIndex returns a slice of all successive match indices of the Regexp in b.

func (*Regexp) FindAllString

func (r *Regexp) FindAllString(s string, n int) []string

FindAllString returns a slice of all successive matches of the Regexp in s.

func (*Regexp) FindAllStringIndex

func (r *Regexp) FindAllStringIndex(s string, n int) [][]int

FindAllStringIndex returns a slice of all successive match indices of the Regexp in s.

func (*Regexp) FindAllStringSubmatch

func (r *Regexp) FindAllStringSubmatch(s string, n int) [][]string

FindAllStringSubmatch returns a slice of all successive matches of the Regexp in s and their submatches.

func (*Regexp) FindAllStringSubmatchIndex

func (r *Regexp) FindAllStringSubmatchIndex(s string, n int) [][]int

FindAllStringSubmatchIndex returns a slice of all successive match index pairs of the Regexp in s and their submatches.

func (*Regexp) FindAllSubmatch

func (r *Regexp) FindAllSubmatch(b []byte, n int) [][][]byte

FindAllSubmatch returns a slice of all successive matches of the Regexp in b and their submatches.

func (*Regexp) FindAllSubmatchIndex

func (r *Regexp) FindAllSubmatchIndex(b []byte, n int) [][]int

FindAllSubmatchIndex returns a slice of all successive match index pairs of the Regexp in b and their submatches.

func (*Regexp) FindIndex

func (r *Regexp) FindIndex(b []byte) []int

FindIndex returns a two-element slice with the start and end index of the leftmost match in b.

func (*Regexp) FindString

func (r *Regexp) FindString(s string) string

FindString returns the leftmost match of the Regexp in s.

func (*Regexp) FindStringIndex

func (r *Regexp) FindStringIndex(s string) []int

FindStringIndex returns a two-element slice with the start and end index of the leftmost match in s.

func (*Regexp) FindStringSubmatch

func (r *Regexp) FindStringSubmatch(s string) []string

FindStringSubmatch returns the leftmost match of the Regexp in s and its submatches as strings.

func (*Regexp) FindStringSubmatchIndex

func (r *Regexp) FindStringSubmatchIndex(s string) []int

FindStringSubmatchIndex returns the index pairs identifying the leftmost match of the Regexp in s and its submatches.

func (*Regexp) FindSubmatch

func (r *Regexp) FindSubmatch(b []byte) [][]byte

FindSubmatch returns slices identifying the leftmost match of the Regexp in b and its submatches.

func (*Regexp) FindSubmatchIndex

func (r *Regexp) FindSubmatchIndex(b []byte) []int

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

func (r *Regexp) Match(b []byte) bool

Match reports whether the byte slice b contains any match of the Regexp.

func (*Regexp) MatchString

func (r *Regexp) MatchString(s string) bool

MatchString reports whether the string s contains any match of the Regexp.

func (*Regexp) NumSubexp

func (r *Regexp) NumSubexp() int

NumSubexp returns the number of parenthesized subexpressions in this Regexp.

func (*Regexp) ReplaceAll

func (r *Regexp) ReplaceAll(src []byte, repl []byte) []byte

ReplaceAll returns a copy of src, replacing matches of the Regexp with repl.

func (*Regexp) ReplaceAllString

func (r *Regexp) ReplaceAllString(src, repl string) string

ReplaceAllString returns a copy of src, replacing matches of the Regexp with repl.

func (*Regexp) Split

func (r *Regexp) Split(s string, n int) []string

Split slices s into substrings separated by the Regexp.

func (*Regexp) String

func (r *Regexp) String() string

String returns the source pattern used to compile the Regexp.

func (*Regexp) SubexpNames

func (r *Regexp) SubexpNames() []string

SubexpNames returns the names of the parenthesized subexpressions in this Regexp. The name for the first sub-expression is names[1].

Source Files

  • doc.go
  • regexp.go
  • utils.go

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL