diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-08-18 01:57:02 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-08-18 01:57:02 +0900 |
| commit | 7061051e19dc0ccbbdb694f030aedb05802287e4 (patch) | |
| tree | 50865f241ee5837312c80b1d007b21319b70950a /docs/dev | |
| parent | a01330572b985007acae339817d171a6505bb16b (diff) | |
| download | php-shirabe-7061051e19dc0ccbbdb694f030aedb05802287e4.tar.gz php-shirabe-7061051e19dc0ccbbdb694f030aedb05802287e4.tar.zst php-shirabe-7061051e19dc0ccbbdb694f030aedb05802287e4.zip | |
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) <noreply@anthropic.com>
Diffstat (limited to 'docs/dev')
| -rw-r--r-- | docs/dev/regex-porting.md | 13 |
1 files changed, 13 insertions, 0 deletions
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, |
