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: 1

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

type PCRE *pcre.Regexp

type RE2

type RE2 *regexp.Regexp

type Regexp

type Regexp struct {
	PCRE *pcre.Regexp
	RE2  *regexp.Regexp
}

func Comp

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

Comp compiles a regular expression and store it in the cache

func CompTry

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

CompTry 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) RepFunc

func (reg *Regexp) 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 (*Regexp) RepStr

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

RepStr 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) RepStrComp

func (reg *Regexp) 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

func (*Regexp) Split

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

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

Jump to

Keyboard shortcuts

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