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 ¶
- func Match(pattern string, b []byte) (matched bool, err error)
- func MatchReader(pattern string, r io.RuneReader) (matched bool, err error)
- func MatchString(pattern string, s string) (matched bool, err error)
- type Regexp
- func (r *Regexp) Close()
- func (r *Regexp) Expand(dst []byte, template []byte, src []byte, match []int) []byte
- func (r *Regexp) ExpandString(dst []byte, template string, src string, match []int) []byte
- 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) FindReaderIndex(reader io.RuneReader) []int
- func (r *Regexp) FindReaderSubmatchIndex(reader io.RuneReader) []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) IsPCRE() bool
- func (r *Regexp) LiteralPrefix() (prefix string, complete bool)
- func (r *Regexp) Longest()
- func (r *Regexp) MarshalText() ([]byte, error)
- func (r *Regexp) Match(b []byte) bool
- func (r *Regexp) MatchReader(reader io.RuneReader) bool
- func (r *Regexp) MatchString(s string) bool
- func (r *Regexp) NumSubexp() int
- func (r *Regexp) ReplaceAll(src, repl []byte) []byte
- func (r *Regexp) ReplaceAllFunc(src []byte, repl func([]byte) []byte) []byte
- func (r *Regexp) ReplaceAllLiteral(src, repl []byte) []byte
- func (r *Regexp) ReplaceAllLiteralString(src, repl string) string
- func (r *Regexp) ReplaceAllString(src, repl string) string
- func (r *Regexp) ReplaceAllStringFunc(src string, repl func(string) string) string
- func (r *Regexp) Split(s string, n int) []string
- func (r *Regexp) String() string
- func (r *Regexp) SubexpIndex(name string) int
- func (r *Regexp) SubexpNames() []string
- func (r *Regexp) UnmarshalText(text []byte) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Match ¶ added in v0.2.0
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.
Types ¶
type Regexp ¶
type Regexp struct {
// contains filtered or unexported fields
}
Regexp is the representation of a compiled regular expression.
func MustCompile ¶
func (*Regexp) Close ¶
func (r *Regexp) Close()
Close releases any resources used by the pcregexp.PCREgexp.
func (*Regexp) ExpandString ¶
func (*Regexp) FindAllStringSubmatch ¶
func (*Regexp) FindAllStringSubmatchIndex ¶
func (*Regexp) FindAllSubmatchIndex ¶
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 (*Regexp) FindStringIndex ¶
func (*Regexp) FindStringSubmatch ¶
func (*Regexp) FindStringSubmatchIndex ¶
func (*Regexp) FindSubmatch ¶
func (*Regexp) FindSubmatchIndex ¶
func (*Regexp) LiteralPrefix ¶
func (*Regexp) MarshalText ¶
func (*Regexp) MatchReader ¶
func (r *Regexp) MatchReader(reader io.RuneReader) bool