From 7061051e19dc0ccbbdb694f030aedb05802287e4 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Tue, 18 Aug 2026 01:57:02 +0900 Subject: refactor(preg): anchor A patterns at the call site The shim carried the PCRE A (anchored) modifier alongside every compiled pattern so preg_match2 could honour it by searching the sub-slice at the offset. Only two call sites ever passed such a pattern, and each can cut that slice itself, so the flag is gone from the cache, ResolvedPattern, PregPattern and the php_regex! macro, and a pattern still carrying A is now rejected rather than silently searched unanchored. StringInput::tokenize and PhpFileCleaner::match search from their cursor with a `^`-prefixed pattern instead. The rule is written down in docs/dev/regex-porting.md. Co-Authored-By: Claude Opus 5 (1M context) --- docs/dev/regex-porting.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'docs/dev/regex-porting.md') diff --git a/docs/dev/regex-porting.md b/docs/dev/regex-porting.md index 45033044..d0686982 100644 --- a/docs/dev/regex-porting.md +++ b/docs/dev/regex-porting.md @@ -27,6 +27,19 @@ for performance, replace it with the plain quantifier (`+`, `*`, `?`). The `regex` crate never backtracks, so it has no possessive quantifiers and has no need for them. +## `A` (anchored) modifier + +The PCRE `A` modifier requires the match to start exactly at the search offset. The `regex` crate +anchors a pattern only at the head of the haystack. + +Port such a pattern by searching the sub-slice that begins at the offset, with a `^` in place of +the `A` modifier: + +```rust +// PHP: preg_match('/foo/A', $subject, offset: $offset) +preg_match(php_regex!(r"/^foo/"), &subject[offset..]) +``` + ## Port other unsupported features ad hoc For any other PCRE feature the `regex` crate does not support (conditional subpatterns, -- cgit v1.3.1-4-g156e