regex

package module
v2.0.4 Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2022 License: MIT Imports: 10 Imported by: 1

README

Go Regex

donation link

A High Performance PCRE Regex Package That Uses A Cache.

Simplifies the the go-pcre regex package. After calling a regex, the compiled output gets cached to improve performance.

This package uses the go-pcre package for better performance.

Installation


  sudo apt-get install libpcre3-dev
  go get github.com/AspieSoft/go-regex

Usage


import (
  "github.com/AspieSoft/go-regex"
)

// pre compile a regex into the cache
// this method also returns the compiled pcre.Regexp struct
regex.Compile(`re`)

// run a replace function (most advanced feature)
regex.RepFunc(myByteArray, `(?flags)re(capture group)`, func(data func(int) []byte) []byte {
  data(0) // get the string
  data(1) // get the first capture group

  return []byte("")

  // if the last option is true, returning nil will stop the loop early
  return nil
}, true /* optional: if true, will not process a return output */)

// run a simple light replace function
regex.RepStr(myByteArray, `re`, myReplacementByteArray)

// return a bool if a regex matches a byte array
regex.Match(myByteArray, `re`)

// split a byte array in a similar way to JavaScript
regex.Split(myByteArray, `re|(keep this and split like in JavaScript)`)

// a regex string is modified before compiling, to add a few other features
`use \' in place of ` + "`" + ` to make things easier`
`(?#This is a comment in regex)`

// an alias of pcre.Regexp
regex.Regexp


// another helpful function
// this method makes it easier to return results to a regex function
regex.JoinBytes("string", []byte("byte array"), 10, 'c', data(2))

// the above method can be used in place of
append(append(append(append([]byte("string"), []byte("byte array")...), []byte(strconv.Itoa(10))...), 'c'), data(2)...)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AutoInstallLinuxDependencies

func AutoInstallLinuxDependencies()

func JoinBytes

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

An easy way to join multiple values into a single []byte accepts: []byte, byte, int32, string, [][]byte, int, int64, float64, float32

func Match

func Match(str []byte, re string) bool

Returns true if a string matches a regex

func MatchRef

func MatchRef(str *[]byte, re string) bool

Returns true if a string matches a regex Uses Pointers For Improved Performance

func RepFunc

func RepFunc(str []byte, re string, rep func(data func(int) []byte) []byte, blank ...bool) []byte

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

func RepFuncFirst

func RepFuncFirst(str []byte, re string, rep func(func(int) []byte) []byte, blank ...bool) []byte

a copy of the RepFunc method modified to only run once

func RepFuncRef

func RepFuncRef(str *[]byte, re string, rep func(data func(int) []byte) []byte, blank ...bool) []byte

Replace a string with the result of a function similar to JavaScript .replace(/re/, function(data){}) Uses Pointers For Improved Performance

func RepStr

func RepStr(str []byte, re string, rep []byte) []byte

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

func RepStrComplex

func RepStrComplex(str []byte, re string, rep []byte) []byte

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 RepStrComplexRef

func RepStrComplexRef(str *[]byte, re string, rep []byte) []byte

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 Uses Pointers For Improved Performance

func RepStrComplexRefRes

func RepStrComplexRefRes(str *[]byte, re string, rep *[]byte) []byte

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 Uses Pointers For Improved Performance (also on result)

func RepStrRef

func RepStrRef(str *[]byte, re string, rep []byte) []byte

Replace with a string note: this function is optimized for performance, and the replacement string does not accept replacements like $1 Uses Pointers For Improved Performance

func RepStrRefRes

func RepStrRefRes(str *[]byte, re string, rep *[]byte) []byte

Replace with a string note: this function is optimized for performance, and the replacement string does not accept replacements like $1 Uses Pointers For Improved Performance (also on result)

func Split

func Split(str []byte, re string) [][]byte

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

func SplitRef

func SplitRef(str *[]byte, re string) [][]byte

Splits a string, and keeps capture groups Similar to JavaScript .split(/re/) Uses Pointers For Improved Performance

Types

type Regexp

type Regexp = pcre.Regexp

func Compile

func Compile(re string) Regexp

Compile a regular expression and store it in the cache

Jump to

Keyboard shortcuts

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