regexp

package
v0.4.21 Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2025 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package regexp wraps the go regexp package with a few additional features: - Support for re2 syntax - Backtracking + compatibility with Perl5 and .NET syntax via github.com/dlclark/regexp2

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type EngineType

type EngineType string

EngineType represents the type of regexp engine to use

const (
	// EngineStandard uses the standard Go regexp engine
	EngineStandard EngineType = "standard"
	// EngineRegexp2 uses the regexp2 engine for .NET-style regex
	EngineRegexp2 EngineType = "regexp2"
	// EngineRE2 uses the RE2 engine for linear time matching
	EngineRE2 EngineType = "re2"
	// EngineAuto automatically selects the most appropriate engine
	EngineAuto EngineType = "auto"
)

type Option

type Option func(*Regexp)

Option represents a configuration option for the regexp

func WithEngine

func WithEngine(engine EngineType) Option

WithEngine sets the regexp engine type

type Regexp

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

Regexp represents an extended regular expression with additional options

func Compile

func Compile(pattern string, opts ...Option) (*Regexp, error)

Compile creates a new Regexp with the given pattern and options

func (*Regexp) Find

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

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

func (*Regexp) FindString

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

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

func (*Regexp) FindStringSubmatch

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

FindStringSubmatch returns a slice of strings holding the text of the leftmost match of the regular expression in s and the matches of its subexpressions.

func (*Regexp) FindStringSubmatchIndex

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

FindStringSubmatchIndex returns a slice holding the index pairs identifying the leftmost match of the regular expression in s and the matches of its subexpressions.

func (*Regexp) Match

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

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

func (*Regexp) MatchString

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

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

func (*Regexp) String

func (r *Regexp) String() string

String returns the original regular expression pattern. For standard and RE2 engines, it calls their String() method. For Regexp2, it returns the stored pattern as Regexp2.String() returns the FSM.

Jump to

Keyboard shortcuts

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