rubex

package module
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: May 6, 2020 License: MIT Imports: 10 Imported by: 0

README

go-oniguruma Test

This repository is a fork of moovweb/rubex - a simple regular expression library (based on oniguruma) that supports Ruby's regex syntax.

The rubex was originally created by Zhigang Chen (zhigang.chen@moovweb.com or zhigangc@gmail.com). It implements all the public functions of Go's Regexp package, except LiteralPrefix.

By the benchmark tests in regexp, the library is 40% to 10X faster than Regexp on all but one test. Unlike Go's regexp, this library supports named capture groups and also allow "\\1" and "\\k<name>" in replacement strings. The library calls the oniguruma regex library for regex pattern searching. All replacement code is done in Go.

Install

# linux (debian/ubuntu/...)
sudo apt-get install libonig-dev

# osx (homebrew)
brew install oniguruma

go get github.com/go-enry/go-oniguruma

License

Apache License Version 2.0, see LICENSE

Documentation

Index

Constants

View Source
const (
	ONIG_OPTION_DEFAULT = ONIG_OPTION_NONE
	/* options */
	ONIG_OPTION_NONE               = 0
	ONIG_OPTION_IGNORECASE         = 1
	ONIG_OPTION_EXTEND             = (ONIG_OPTION_IGNORECASE << 1)
	ONIG_OPTION_MULTILINE          = (ONIG_OPTION_EXTEND << 1)
	ONIG_OPTION_SINGLELINE         = (ONIG_OPTION_MULTILINE << 1)
	ONIG_OPTION_FIND_LONGEST       = (ONIG_OPTION_SINGLELINE << 1)
	ONIG_OPTION_FIND_NOT_EMPTY     = (ONIG_OPTION_FIND_LONGEST << 1)
	ONIG_OPTION_NEGATE_SINGLELINE  = (ONIG_OPTION_FIND_NOT_EMPTY << 1)
	ONIG_OPTION_DONT_CAPTURE_GROUP = (ONIG_OPTION_NEGATE_SINGLELINE << 1)
	ONIG_OPTION_CAPTURE_GROUP      = (ONIG_OPTION_DONT_CAPTURE_GROUP << 1)
	/* options (search time) */
	ONIG_OPTION_NOTBOL       = (ONIG_OPTION_CAPTURE_GROUP << 1)
	ONIG_OPTION_NOTEOL       = (ONIG_OPTION_NOTBOL << 1)
	ONIG_OPTION_POSIX_REGION = (ONIG_OPTION_NOTEOL << 1)
	ONIG_OPTION_MAXBIT       = ONIG_OPTION_POSIX_REGION /* limit */

	ONIG_NORMAL   = 0
	ONIG_MISMATCH = -1

	ONIG_MISMATCH_STR                = "mismatch"
	ONIGERR_UNDEFINED_NAME_REFERENCE = -217
)

Variables

This section is empty.

Functions

func MatchString

func MatchString(pattern string, s string) (matched bool, error error)

func QuoteMeta

func QuoteMeta(s string) string

QuoteMeta returns a string that quotes all regular expression metacharacters inside the argument text; the returned string is a regular expression matching the literal text. For example, QuoteMeta(`[foo]`) returns `\[foo\]`.

Types

type NamedGroupInfo

type NamedGroupInfo map[string]int

type Regexp

type Regexp struct {
	// contains filtered or unexported fields
}

func Compile

func Compile(str string) (*Regexp, error)

func CompileWithOption

func CompileWithOption(str string, option int) (*Regexp, error)

func MustCompile

func MustCompile(str string) *Regexp

func MustCompileASCII

func MustCompileASCII(str string) *Regexp

MustCompileASCII is equivalent to MustCompile, but with the encoding restricted to ASCII.

func MustCompileWithOption

func MustCompileWithOption(str string, option int) *Regexp

func NewRegexp

func NewRegexp(pattern string, option int) (*Regexp, error)

NewRegexp creates and initializes a new Regexp with the given pattern and option.

func NewRegexpASCII

func NewRegexpASCII(pattern string, option int) (*Regexp, error)

NewRegexpASCII is equivalent to NewRegexp, but with the encoding restricted to ASCII.

func (*Regexp) Find

func (re *Regexp) Find(b []byte) []byte

func (*Regexp) FindAll

func (re *Regexp) FindAll(b []byte, n int) [][]byte

func (*Regexp) FindAllIndex

func (re *Regexp) FindAllIndex(b []byte, n int) [][]int

func (*Regexp) FindAllString

func (re *Regexp) FindAllString(s string, n int) []string

func (*Regexp) FindAllStringIndex

func (re *Regexp) FindAllStringIndex(s string, n int) [][]int

func (*Regexp) FindAllStringSubmatch

func (re *Regexp) FindAllStringSubmatch(s string, n int) [][]string

func (*Regexp) FindAllStringSubmatchIndex

func (re *Regexp) FindAllStringSubmatchIndex(s string, n int) [][]int

func (*Regexp) FindAllSubmatch

func (re *Regexp) FindAllSubmatch(b []byte, n int) [][][]byte

func (*Regexp) FindAllSubmatchIndex

func (re *Regexp) FindAllSubmatchIndex(b []byte, n int) [][]int

func (*Regexp) FindIndex

func (re *Regexp) FindIndex(b []byte) []int

func (*Regexp) FindReaderIndex

func (re *Regexp) FindReaderIndex(r io.RuneReader) []int

func (*Regexp) FindReaderSubmatchIndex

func (re *Regexp) FindReaderSubmatchIndex(r io.RuneReader) []int

func (*Regexp) FindString

func (re *Regexp) FindString(s string) string

func (*Regexp) FindStringIndex

func (re *Regexp) FindStringIndex(s string) []int

func (*Regexp) FindStringSubmatch

func (re *Regexp) FindStringSubmatch(s string) []string

func (*Regexp) FindStringSubmatchIndex

func (re *Regexp) FindStringSubmatchIndex(s string) []int

func (*Regexp) FindSubmatch

func (re *Regexp) FindSubmatch(b []byte) [][]byte

func (*Regexp) FindSubmatchIndex

func (re *Regexp) FindSubmatchIndex(b []byte) []int

func (*Regexp) Free

func (re *Regexp) Free()

func (*Regexp) Gsub

func (re *Regexp) Gsub(src, repl string) string

func (*Regexp) GsubFunc

func (re *Regexp) GsubFunc(src string, replFunc func(string, map[string]string) string) string

func (*Regexp) LiteralPrefix

func (re *Regexp) LiteralPrefix() (prefix string, complete bool)

func (*Regexp) Match

func (re *Regexp) Match(b []byte) bool

func (*Regexp) MatchReader

func (re *Regexp) MatchReader(r io.RuneReader) bool

func (*Regexp) MatchString

func (re *Regexp) MatchString(s string) bool

func (*Regexp) NumSubexp

func (re *Regexp) NumSubexp() int

func (*Regexp) ReplaceAll

func (re *Regexp) ReplaceAll(src, repl []byte) []byte

func (*Regexp) ReplaceAllFunc

func (re *Regexp) ReplaceAllFunc(src []byte, repl func([]byte) []byte) []byte

func (*Regexp) ReplaceAllString

func (re *Regexp) ReplaceAllString(src, repl string) string

func (*Regexp) ReplaceAllStringFunc

func (re *Regexp) ReplaceAllStringFunc(src string, repl func(string) string) string

func (*Regexp) String

func (re *Regexp) String() string

Jump to

Keyboard shortcuts

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