14 chars · 1 line
8 chars · 1 line
14 chars · 1 line
8 chars · 1 line
Regex matching behavior
A regex can compile perfectly and still be too permissive. The pattern admin matches any input containing that substring, including superadminuser. Add start and end anchors when the whole value must satisfy the pattern. This tool is free to use. No account or payment is required.
Last updated
JavaScript RegExp test() succeeds when any part of the input matches. Anchors change that boundary rule: ^ requires the match to start at the beginning and $ requires it to finish at the end.
The original pattern accepts text around admin; the corrected pattern requires exactly admin.
admin^admin$Common questions
Because an unanchored regex searches for a matching substring anywhere in the input.
Without the m flag they describe the input boundaries. With m, they can also match line boundaries.
When the complete value must follow the format, explicit boundaries are usually clearer than relying on a substring match.
Debugging a specific Regex issue? Browse Regex troubleshooting.