netregex

package
v0.10.0-dev.21 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2026 License: AGPL-3.0 Imports: 10 Imported by: 0

Documentation

Overview

Package netregex runs .NET-flavour regular expressions with .NET's match semantics, as dlclark/regexp2 defines them, in polynomial time.

Go's regexp/syntax compiles each pattern and a Pike VM runs it with .NET's assertions: Unicode \b, \B, \w, \d and \s, and $ also before a final \n. Each lookaround is a position predicate over the whole input, memoized per call. A lookbehind costs one pass over the input; a lookahead one anchored run per position it is asked at. For an n-byte input and a pattern whose programs hold m instructions in all, a call is O(n²·m); release names are clamped to 512 bytes. Backreferences, atomic groups, conditionals, inline options other than (?i:) and (?-i:), and a named group in a loop that can match empty are refused at Compile.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsWordChar

func IsWordChar(r rune) bool

IsWordChar reports whether r is a .NET word character: what \w matches and \b and \B test on each side.

Types

type Options

type Options struct {
	IgnoreCase              bool
	IgnorePatternWhitespace bool
}

Options are the RegexOptions that change a pattern's meaning.

type Regexp

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

Regexp is a compiled pattern; it is safe for concurrent use.

func Compile

func Compile(pattern string, o Options) (*Regexp, error)

Compile reads a .NET pattern; the error is an *UnsupportedError for a construct the executor does not run.

func (*Regexp) Find

func (re *Regexp) Find(s string, from int) []int

Find is .NET's Match(s, from): the leftmost match starting at or after byte from, the text before from still in view, as byte offsets in the SubexpNames order (-1 for a group that took no part); nil when none.

func (*Regexp) FindAll

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

FindAll is .NET's Matches: each search starts where the last match ended, one rune further after an empty one.

func (*Regexp) MatchString

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

MatchString is .NET's IsMatch.

func (*Regexp) Replace

func (re *Regexp) Replace(s, replacement string) string

Replace is .NET's Replace with a literal replacement: no $ substitution.

func (*Regexp) SubexpIndex

func (re *Regexp) SubexpIndex(name string) int

SubexpIndex returns the index of the named group, or -1.

func (*Regexp) SubexpNames

func (re *Regexp) SubexpNames() []string

SubexpNames returns each group's name by its index in a match: index 0 is the whole match, and a name used twice in the pattern is one group.

type UnsupportedError

type UnsupportedError struct{ Construct string }

UnsupportedError names a .NET construct the executor does not run.

func (*UnsupportedError) Error

func (e *UnsupportedError) Error() string

Jump to

Keyboard shortcuts

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