compat

package
v2.1.0 Latest Latest
Warning

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

Go to latest
Published: May 22, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package compat provides a regexp2 adapter with regexp.Regexp-compatible matching method signatures.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Matcher

type Matcher interface {
	Match(b []byte) bool
	MatchString(s string) bool
	MatchReader(r io.RuneReader) bool

	Find(b []byte) []byte
	FindIndex(b []byte) []int
	FindReaderIndex(r io.RuneReader) []int
	FindReaderSubmatchIndex(r io.RuneReader) []int
	FindString(s string) string
	FindStringIndex(s string) []int
	FindStringSubmatch(s string) []string
	FindStringSubmatchIndex(s string) []int
	FindSubmatch(b []byte) [][]byte
	FindSubmatchIndex(b []byte) []int

	FindAll(b []byte, n int) [][]byte
	FindAllIndex(b []byte, n int) [][]int
	FindAllString(s string, n int) []string
	FindAllStringIndex(s string, n int) [][]int
	FindAllStringSubmatch(s string, n int) [][]string
	FindAllStringSubmatchIndex(s string, n int) [][]int
	FindAllSubmatch(b []byte, n int) [][][]byte
	FindAllSubmatchIndex(b []byte, n int) [][]int
}

Matcher is the common matching interface implemented by regexp.Regexp and this package's Regexp adapter.

It includes the standard-library matching surface: Match, MatchString, MatchReader, and all Find(All)?(String)?(Submatch)?(Index)? methods.

type Regexp

type Regexp struct {
	// contains filtered or unexported fields
}

Regexp adapts a regexp2.Regexp to the matching method signatures of regexp.Regexp.

The wrapped regexp2 engine can return match-time errors, most commonly timeouts. Since regexp.Regexp matching methods do not return errors, this adapter panics if the wrapped regexp2 matcher returns one.

func Compile

func Compile(expr string, options ...regexp2.CompileOption) (*Regexp, error)

Compile parses a regular expression and returns a compat adapter for it.

func MustCompile

func MustCompile(str string, options ...regexp2.CompileOption) *Regexp

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

func Wrap

func Wrap(re *regexp2.Regexp) *Regexp

Wrap returns an adapter around re.

func (*Regexp) Find

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

Find returns a slice holding the text of the leftmost match in b.

func (*Regexp) FindAll

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

FindAll returns a slice of all successive matches in b.

func (*Regexp) FindAllIndex

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

FindAllIndex returns a slice of byte index pairs for all successive matches in b.

func (*Regexp) FindAllString

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

FindAllString returns a slice of all successive matches in s.

func (*Regexp) FindAllStringIndex

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

FindAllStringIndex returns a slice of byte index pairs for all successive matches in s.

func (*Regexp) FindAllStringSubmatch

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

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

func (*Regexp) FindAllStringSubmatchIndex

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

FindAllStringSubmatchIndex returns a slice of byte index pairs for all successive matches and their submatches in s.

func (*Regexp) FindAllSubmatch

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

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

func (*Regexp) FindAllSubmatchIndex

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

FindAllSubmatchIndex returns a slice of byte index pairs for all successive matches and their submatches in b.

func (*Regexp) FindIndex

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

FindIndex returns a two-element slice defining the location of the leftmost match in b.

func (*Regexp) FindReaderIndex

func (re *Regexp) FindReaderIndex(r io.RuneReader) []int

FindReaderIndex returns a two-element slice defining the byte location of the leftmost match in text read from r.

func (*Regexp) FindReaderSubmatchIndex

func (re *Regexp) FindReaderSubmatchIndex(r io.RuneReader) []int

FindReaderSubmatchIndex returns a slice holding the byte index pairs of the leftmost match and its submatches in text read from r.

func (*Regexp) FindString

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

FindString returns a string holding the text of the leftmost match in s.

func (*Regexp) FindStringIndex

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

FindStringIndex returns a two-element slice defining the location of the leftmost match in s.

func (*Regexp) FindStringSubmatch

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

FindStringSubmatch returns a slice of strings holding the text of the leftmost match and its submatches.

func (*Regexp) FindStringSubmatchIndex

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

FindStringSubmatchIndex returns a slice holding the byte index pairs of the leftmost match and its submatches.

func (*Regexp) FindSubmatch

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

FindSubmatch returns a slice of byte slices holding the text of the leftmost match and its submatches.

func (*Regexp) FindSubmatchIndex

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

FindSubmatchIndex returns a slice holding the byte index pairs of the leftmost match and its submatches.

func (*Regexp) Match

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

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

func (*Regexp) MatchReader

func (re *Regexp) MatchReader(r io.RuneReader) bool

MatchReader reports whether text returned by r contains any match of the regular expression.

func (*Regexp) MatchString

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

MatchString reports whether the string s contains any match of the regular expression.

func (*Regexp) String

func (re *Regexp) String() string

String returns the source text used to compile the regular expression.

func (*Regexp) Unwrap

func (re *Regexp) Unwrap() *regexp2.Regexp

Unwrap returns the wrapped regexp2 regular expression.

Jump to

Keyboard shortcuts

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