Documentation
¶
Overview ¶
Package regexpjs is the JS→regex translation layer: it parses/validates ECMAScript regular expressions and retargets them onto dlclark/regexp2, with translate-time expansion of property escapes (UCD 17.0) and v-flag set notation, sticky/anchored program variants, and ported RegExp.$1-$9 statics. See PLAN.md Phase 4.3 / 8.
Package regexpjs is the JS→regex translation layer (PLAN.md Phase 4.3/8): it validates ECMAScript regular expressions and retargets them onto dlclark/regexp2 (which supports an ECMAScript mode directly). Flags g/y and lastIndex handling live at the JS level; i/m/s/u map to regexp2 options.
Position semantics: subjects are passed in — and all offsets reported back — as UTF-16 code units, the domain ECMAScript indexes strings in. A `u`/`v` pattern matches whole code points, so Exec recodes such a subject and maps the resulting offsets back (see Exec).
regexp2 is the reference matcher, but not always the one that runs: re2.go translates the patterns it can into RE2 syntax for Go's own regexp, which is several times faster, and works out a literal run that any match must contain so a long subject without one can be rejected without matching at all.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var VerifyFast bool
VerifyFast makes every fast-path match run the regexp2 matcher as well and panic if the two disagree. It is a test hook, not a knob: the cost is running both engines.
Functions ¶
func UnicodeBinaryProperty ¶
func UnicodeBinaryProperty(name string) *unicode.RangeTable
UnicodeBinaryProperty returns the code-point set of a Unicode binary property by its canonical name ("Cased", "Case_Ignorable", …), or nil if there is no such property. It exposes the generated tables to callers outside the regexp engine — String.prototype.toLowerCase needs Cased / Case_Ignorable to decide the Final_Sigma context.
Types ¶
type Regexp ¶
type Regexp struct {
Source string
Flags string
Global bool
IgnoreCase bool
Multiline bool
DotAll bool
Unicode bool
UnicodeSets bool
Sticky bool
// contains filtered or unexported fields
}
Regexp is a compiled JS regular expression.
func (*Regexp) Exec ¶
Exec runs the regex against input — the subject string as UTF-16 code units, one rune per unit — starting at code-unit index start, and returns the first match (or nil if none). Sticky matches must begin exactly at start. All returned offsets are code-unit indices, matching ECMAScript string indexing.
func (*Regexp) ExecASCII ¶
ExecASCII is Exec for a subject already known to be pure ASCII, run on the translated pattern. handled is false when the call is not one the fast path can take — no translation, or a search from a nonzero offset by a pattern that reads text to the left of it — and the caller must fall back to Exec.
func (*Regexp) GroupCount ¶
GroupCount returns the number of capture groups (excluding group 0).