regex

package
v2.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2023 License: MIT Imports: 5 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 RE2

type RE2 *regexp.Regexp

type Regexp

type Regexp struct {
	RE *regexp.Regexp
	// contains filtered or unexported fields
}

func Compile

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

Comp compiles a regular expression and store it in the cache

func CompileTry

func CompileTry(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) ReplaceFileFunc added in v2.1.2

func (reg *Regexp) ReplaceFileFunc(name string, rep func(data func(int) []byte) []byte, all bool, maxReSize ...int64) error

ReplaceFileFunc replaces a regex match with the result of a callback function in a file

@all: if true, will replace all text matching @re, if false, will only replace the first occurrence

func (*Regexp) ReplaceFileString added in v2.1.2

func (reg *Regexp) ReplaceFileString(name string, rep []byte, all bool, maxReSize ...int64) error

ReplaceFileString replaces a regex match with a new []byte in a file

@all: if true, will replace all text matching @re, if false, will only replace the first occurrence

func (*Regexp) ReplaceFunc

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

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

ReplaceString 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) ReplaceStringLiteral

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

ReplaceStringLiteral replaces a string with another string

@rep uses the literal string, and does Not use args like $1

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