DELAPARRA
Index
Color
NL
Category: Regex flags

/A (Anchored)

Explained by Updated

What is /A (Anchored)?

/A (Anchored): Forces the pattern to match only at the very start of the subject string (or immediately after the previous match), like an implicit ^. The A modifier anchors a pattern, so it can only match at the start of the text, or right where the previous match ended. It behaves like putting ^ at the beginning, but it also applies to repeated matching.

Definition source Coders Lingo, CC BY 4.0

Frequently asked questions about /A (Anchored)

How is /A (Anchored) used in practice?

You see it mainly in PHP's PCRE functions, as in preg_match('/abc/A', $input). It is useful when you write a small tokenizer that reads a string piece by piece. Each call must continue exactly where the last one stopped, and the anchor prevents the engine from skipping ahead to a later match.

What should you keep in mind with /A (Anchored)?

For everyday validation, ^ and $ are clearer to most readers, so prefer them. Use A when you need its specific behaviour in a loop, and add a comment. Few developers know this flag, and the next person to read the code should not have to look it up.

At a glance

CategoryRegex flags
Explained by
Updated

More Regex flags terms

All terms starting with a number or symbol

Skills

Download all skills (zip)

Manuals

Related services

Need any help?

Stuck on one of these in your own project? Tell me what you are working on and I will tell you how I would approach it.