regex

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2026 License: MIT Imports: 11 Imported by: 1

Documentation

Overview

Package regex provides shared ECMAScript matching and string replacement. It is optional: importing Commons or Data Masking alone does not load it.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Options

type Options struct {
	MatchTimeout             time.Duration
	MaxBacktrackingStackSize int
}

Options configures matching limits. Zero values use the engine defaults: no timeout and a 100,000-entry backtracking stack. A negative stack size removes that bound; a negative timeout is invalid.

type Regexp

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

Regexp is safe for concurrent use. Stateful replacements serialize access to lastIndex; stateless MatchString calls can run concurrently. Do not copy it.

func Compile

func Compile(pattern, flags string, limits Options) (*Regexp, error)

Compile accepts ECMAScript d, g, i, m, s, u and y flags. The d flag has no effect on string replacement. Unicode set syntax (v) is not supported.

func (*Regexp) LastIndex

func (r *Regexp) LastIndex() int

LastIndex returns the UTF-16 offset used by sticky, non-global replacement.

func (*Regexp) MatchString

func (r *Regexp) MatchString(input string) (bool, error)

MatchString searches from the beginning without reading or changing lastIndex. A sticky pattern must match at the beginning.

func (*Regexp) Replace

func (r *Regexp) Replace(input, format string) (string, error)

Replace implements JavaScript string replacement tokens and global/sticky state. Lone UTF-16 surrogates are preserved as WTF-8 bytes in Go strings; encoding/json cannot preserve those bytes as JavaScript string code units.

func (*Regexp) Replacer

func (r *Regexp) Replacer(format string) func(string) (string, error)

Replacer binds a replacement format for use with datamasking.Rule.Replace. The returned callback shares this Regexp's lastIndex.

func (*Regexp) SetLastIndex

func (r *Regexp) SetLastIndex(index int)

SetLastIndex sets an integer UTF-16 offset. Negative values are normalized to zero when used by replacement, as with JavaScript's ToLength operation.

func (*Regexp) String

func (r *Regexp) String() string

Jump to

Keyboard shortcuts

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