A PHP regex compiled once and matched many times: preg_match() without
the per-call cache lookup, for libraries that run fixed patterns on a hot
path (utopia-user-agent runs its tables on every request).
| PHP | Rust |
|---|---|
preg_match($re, $s, $m) === 1, then $m[$n] | Regex::compiled, Regex::captures, Captures::get |
preg_match($re, $s) === 1 | Regex::is_match |
Both run exactly the calls preg_match() makes, so a match that fails
(pcre.backtrack_limit, the JIT stack) is no match, as preg_match()
returning false is not 1. They do not set preg_last_error().
Contents
use php_std::pcre::compiled::Captures;Rust
pub struct Captures<'s>The groups of one match of Regex::captures, as preg_match() puts
them in $matches.