regexp

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: May 16, 2025 License: Apache-2.0 Imports: 4 Imported by: 1

Documentation

Overview

Package regexp provides a drop-in replacement for Go's standard regexp package with added support for Perl-compatible regular expressions (PCRE).

This package automatically selects between using the standard library's regexp engine and a PCRE-based engine (pcregexp package) based on the features used in the regular expression. If the pattern contains PCRE- specific constructs such as lookahead/lookbehind assertions or backreferences, the PCRE engine is employed; otherwise, the standard library implementation is used.

The Regexp type represents a compiled regular expression and wraps either a standard regexp.Regexp or a pcregexp.PCREgexp, exposing a unified API for matching, searching, replacing, and more.

Use this package when you require advanced regex features not supported by the standard library's regexp package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Match added in v0.2.0

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

Match reports whether the byte slice b contains any match of the regular expression pattern. More complicated queries need to use Compile and the full Regexp interface.

func MatchReader added in v0.2.0

func MatchReader(pattern string, r io.RuneReader) (matched bool, err error)

MatchReader reports whether the text returned by the io.RuneReader contains any match of the regular expression pattern. More complicated queries need to use Compile and the full Regexp interface.

func MatchString added in v0.2.0

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

MatchString reports whether the string s contains any match of the regular expression pattern. More complicated queries need to use Compile and the full Regexp interface.

Types

type Regexp

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

Regexp is the representation of a compiled regular expression.

func Compile

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

func MustCompile

func MustCompile(pattern string) *Regexp

func (*Regexp) Close

func (r *Regexp) Close()

Close releases any resources used by the pcregexp.PCREgexp.

func (*Regexp) Expand

func (r *Regexp) Expand(dst []byte, template []byte, src []byte, match []int) []byte

func (*Regexp) ExpandString

func (r *Regexp) ExpandString(dst []byte, template string, src string, match []int) []byte

func (*Regexp) Find

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

func (*Regexp) FindAll

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

func (*Regexp) FindAllIndex

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

func (*Regexp) FindAllString

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

func (*Regexp) FindAllStringIndex

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

func (*Regexp) FindAllStringSubmatch

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

func (*Regexp) FindAllStringSubmatchIndex

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

func (*Regexp) FindAllSubmatch

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

func (*Regexp) FindAllSubmatchIndex

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

func (*Regexp) FindIndex

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

func (*Regexp) FindReaderIndex

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

func (*Regexp) FindReaderSubmatchIndex

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

func (*Regexp) FindString

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

func (*Regexp) FindStringIndex

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

func (*Regexp) FindStringSubmatch

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

func (*Regexp) FindStringSubmatchIndex

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

func (*Regexp) FindSubmatch

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

func (*Regexp) FindSubmatchIndex

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

func (*Regexp) IsPCRE

func (r *Regexp) IsPCRE() bool

IsPCRE reports whether the Regexp is a PCRE.

func (*Regexp) LiteralPrefix

func (r *Regexp) LiteralPrefix() (prefix string, complete bool)

func (*Regexp) Longest

func (r *Regexp) Longest()

func (*Regexp) MarshalText

func (r *Regexp) MarshalText() ([]byte, error)

func (*Regexp) Match

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

func (*Regexp) MatchReader

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

func (*Regexp) MatchString

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

func (*Regexp) NumSubexp

func (r *Regexp) NumSubexp() int

func (*Regexp) ReplaceAll

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

func (*Regexp) ReplaceAllFunc

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

func (*Regexp) ReplaceAllLiteral

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

func (*Regexp) ReplaceAllLiteralString

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

func (*Regexp) ReplaceAllString

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

func (*Regexp) ReplaceAllStringFunc

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

func (*Regexp) Split

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

func (*Regexp) String

func (r *Regexp) String() string

func (*Regexp) SubexpIndex

func (r *Regexp) SubexpIndex(name string) int

func (*Regexp) SubexpNames

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

func (*Regexp) UnmarshalText

func (r *Regexp) UnmarshalText(text []byte) error

Jump to

Keyboard shortcuts

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