Skip to content

Regex Matcher

Spice
import "std/text/regex-matcher";

Thread struct

Pike's-VM matcher: runs a compiled RegexProgram (see "std/text/regex/regex-program") over an input string without backtracking, which bounds matching to O(input length * program size) - no pattern can trigger catastrophic backtracking.

runProgram only tries to match starting exactly at startIndex (i.e. as if the pattern were anchored there); "std/text/regex/regex" implements unanchored search by trying successive start positions.

Fields

Name Type Description
pc long
saved Vector<long>

Constructors

ctor

Spice
public p Thread.ctor(long pc, const Vector<long>& saved)

Parameters

Name Type Description
pc long
saved const Vector<long>&

ctor

Spice
public p Thread.ctor(const Thread& original)

Parameters

Name Type Description
original const Thread&

dtor

Spice
public p Thread.dtor()

ThreadList struct

Fields

Name Type Description
threads Vector<Thread>
lastGen Vector<long>
gen long

Constructors

ctor

Spice
public p ThreadList.ctor(long numInstrs)

Parameters

Name Type Description
numInstrs long

Methods

reset

Spice
public p ThreadList.reset()

Functions

runProgram

Spice
public f<Optional<Vector<long>>> runProgram(const RegexProgram& prog, const String& input, unsigned long startIndex)

Try to match prog against input, starting exactly at startIndex (as if the pattern were anchored there - "std/text/regex/regex" tries successive positions to implement unanchored search). On success, returns the capture-slot array (slot 0/1 = whole-match start/end, slot 2g/2g+1 = group g start/end, -1 where a group did not participate).

Parameters

Name Type Description
prog const RegexProgram& Compiled program to run
input const String& String to match against
startIndex unsigned long Position in input to start matching at

Returns: Optional<Vector<long>> — The capture-slot array of the match with the greatest extent under Perl/PCRE-style leftmost-first priority, or an empty Optional if no match starts at startIndex