regex

package
v5.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2023 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Escape

func Escape(re string) string

Escape will escape regex special chars

func IsValid

func IsValid(str []byte) bool

IsValid will return true if a regex is valid and can compile

func JoinBytes

func JoinBytes(bytes ...interface{}) []byte

JoinBytes is an easy way to join multiple values into a single []byte

Types

type PCRE added in v5.0.1

type PCRE *pcre.Regexp

type RE2 added in v5.0.1

type RE2 *regexp.Regexp

type Regexp

type Regexp struct {
	RE *pcre.Regexp
}

func Compile

func Compile(re string, params ...string) *Regexp

Compile compiles a regular expression and store it in the cache

func CompileTry

func CompileTry(re string, params ...string) (*Regexp, error)

CompileTry tries to compile or returns an error

func (*Regexp) Match

func (reg *Regexp) Match(str []byte) bool

Match returns true if a []byte matches a regex

func (*Regexp) ReplaceFunc

func (reg *Regexp) ReplaceFunc(str []byte, rep func(data func(int) []byte) []byte, blank ...bool) []byte

ReplaceFunc replaces a string with the result of a function similar to JavaScript .replace(/re/, function(data){})

func (*Regexp) ReplaceString

func (reg *Regexp) ReplaceString(str []byte, rep []byte) []byte

ReplaceString replaces a string with another string note: this function is optimized for performance, and the replacement string does not accept replacements like $1

func (*Regexp) ReplaceStringComplex

func (reg *Regexp) ReplaceStringComplex(str []byte, rep []byte) []byte

ReplaceStringComplex is a more complex version of the RepStr method this function will replace things in the result like $1 with your capture groups use $0 to use the full regex capture group use ${123} to use numbers with more than one digit

func (*Regexp) Split

func (reg *Regexp) Split(str []byte) [][]byte

Split splits a string, and keeps capture groups Similar to JavaScript .split(/re/)

type RegexpRE2

type RegexpRE2 struct {
	RE *regexp.Regexp
}

func (*RegexpRE2) RepFunc

func (reg *RegexpRE2) RepFunc(str []byte, rep func(data func(int) []byte) []byte, blank ...bool) []byte

RepFunc replaces a string with the result of a function similar to JavaScript .replace(/re/, function(data){})

func (*RegexpRE2) RepStrComp

func (reg *RegexpRE2) RepStrComp(str []byte, rep []byte) []byte

RepStrComp is a more complex version of the RepStr method this function will replace things in the result like $1 with your capture groups use $0 to use the full regex capture group use ${123} to use numbers with more than one digit

Jump to

Keyboard shortcuts

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