regex

package module
v1.4.4 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2022 License: MIT Imports: 10 Imported by: 1 module, 1 package

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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 added in v1.4.3

func AutoInstallLinuxDependencies()

func Join added in v1.4.1

func Join[T str](bytes ...interface{}) T

An easy way to join multiple values with different types, into a single value with one type accepts: []byte, byte, int32, string, [][]byte, int, int64, float64, float32

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[T str](str T, re string) bool

Returns true if a string matches a regex

func RepFunc

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

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

func RepFuncFirst

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

a copy of the RepFunc method modified to only run once

func RepStr

func RepStr[T str, J str](str T, re string, rep J) J

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

func RepStrComplex added in v1.4.1

func RepStrComplex[T str, J str](str T, re string, rep J, blank ...bool) J

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 Split

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

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

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
⌂ 换网址