rxmatch

package
v0.13.3 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2026 License: Apache-2.0 Imports: 5 Imported by: 0 modules, 0 packages

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.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Matcher

type Matcher interface {
	MatchString(s string) (bool, error)
	FindLine(content string) (int, bool, error)
	// FindIndex reports the byte offset where the first match starts, so a
	// caller can inspect the text immediately before it (params.denied_by,
	// #4). Returns -1 when there is no match; a matcher that cannot report a
	// position returns -1 with ok=true, which the denial stage treats as
	// undecidable and therefore not a denial.
	FindIndex(s string) (int, bool, error)
	// CountMatches reports how many non-overlapping matches s holds. The
	// pair-consistency `countable` obligation needs it: count(requires) must be
	// >= count(trigger) inside a unit, so a second trigger cannot free-ride on
	// one companion. Returns an error for the same reason MatchString does — a
	// regexp2 timeout must not read as "zero matches", which would clear the
	// obligation it was meant to enforce.
	CountMatches(s string) (int, error)
	String() string
}

Package rxmatch is the ONE regex backend every rule type compiles through.

It was internal to package pattern until #17979: pair-consistency compiled with regexp.Compile directly, so `syntax: regexp2` and `multiline: true` were accepted by forbidden-pattern and refused by pair-consistency. A repo converting a rule from one to the other had to drop those params, and dropping multiline SILENTLY DISABLES a cross-line trigger — the rule still loads, still reports OK, and no longer matches anything. Extracting the matcher rather than copying it is the point: two regex backends are how two answers to one question start to disagree.

Matcher matches text (spec §5 pattern semantics). Two backends: Go's RE2 (default — fast, linear-time, no catastrophic backtracking) and the regexp2 engine, opt-in via `syntax: regexp2`, for the minority of rules that need PCRE2 lookaround/backreferences the shell (pcre2) gates used. MatchString is the per-line path; FindLine (used by `multiline: true`) matches over whole file content and returns the 1-based line where the first match starts. Both return an error so a regexp2 backtracking timeout fails closed (exit 2) rather than reading as a clean pass — a rule that failed to evaluate must never look like one that found nothing (#22).

func Compile

func Compile(what, pattern, syntax string) (Matcher, error)

Compile builds a matcher for pattern under syntax: "" or "re2" -> RE2; "regexp2" -> the PCRE2-capable engine (lookaround enabled, 1s match timeout). Any other syntax value is an error (exit-2 config error).

Jump to

Keyboard shortcuts

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