Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Regex Laravel Package

php-standard-library/regex

Type-safe regex for PHP with typed capture groups and predictable error handling. Build expressions with confidence, get structured match results, and avoid silent failures common in preg_* functions. Part of PHP Standard Library.

View on GitHub
Deep Wiki
Context7

Type-safe regular expressions with typed capture groups and proper error handling

Frequently asked questions about Regex
What is php-standard-library/regex and how does it work in Laravel?
It is a type-safe regular expression package that provides typed capture groups, structured match results, and predictable error handling instead of raw preg_* arrays. In Laravel you can use it inside services, custom validation rules, form requests, and queued jobs, but it does not ship native Blade directives, validation message integration, or service container bindings. You will typically wrap it in your own Laravel-specific helpers or rule classes.
How do I install php-standard-library/regex in a Laravel project?
Install it with Composer using composer require php-standard-library/regex. The package is a plain PHP library rather than a Laravel-specific package, so no dedicated Laravel service provider is documented in the overview. After installation, use its classes directly in your application code or custom validation rules.
Which Laravel and PHP versions are supported by php-standard-library/regex?
The provided documentation does not list Laravel version constraints or a Laravel support matrix. It is part of the PHP Standard Library and is not described as a Laravel-specific package, so compatibility depends on its PHP requirements. Check the package composer.json and release notes before adopting it in a Laravel application.
Can I use php-standard-library/regex for Laravel validation rules and form requests?
Yes, you can use it inside custom Rule objects or FormRequest logic to replace preg_match calls that parse or validate input. However, it does not natively integrate with Laravel validation error messages, so you must catch exceptions or convert failed match results into ValidationException yourself. It is most useful for validation that needs typed captures or structured match results.
How do typed capture groups work compared to preg_match?
Typed capture groups let you define expected captures and receive structured match results instead of relying on numeric or named array indexes from preg_match. This reduces array-shape mistakes and makes parsing code easier to unit test. For simple one-off matches, raw preg_* functions may still be simpler and more familiar.
How does error handling differ from preg_* and preg_last_error in Laravel?
The package standardizes failures with exceptions for invalid patterns and predictable error responses rather than relying on the ambiguity of preg_last_error. In Laravel you can catch those exceptions and map them to ValidationException or application logging. This improves debugging, but it requires explicit integration work with Laravel's error format.
Is php-standard-library/regex good for production Laravel applications?
It can be used in production, but the technical evaluation flags API stability risk and a lack of Laravel-specific benchmarks. Start with a pilot module such as user input validation and benchmark regex-heavy paths against raw preg_* calls. Pin package versions and keep a fallback to raw PCRE for edge cases.
How do I test regex logic with php-standard-library/regex in PHPUnit?
Structured MatchResult objects make assertions clearer because you can assert typed capture values directly instead of comparing raw preg_match arrays. You can also test that invalid patterns throw exceptions. Existing tests that expect preg_* array shapes may need updates when migrating.
Does php-standard-library/regex replace Laravel's built-in regex validation rule?
No, it does not replace Laravel's built-in regex validation rule or natively integrate with the Validator. It is a lower-level library for building custom validation and parsing logic. Use it inside custom rules when you need typed capture groups or structured error handling.
What are the alternatives to php-standard-library/regex for regex in Laravel?
Alternatives include raw preg_* functions, Laravel's built-in regex validation rule, and other typed regex wrappers. The trade-off is type safety and structured errors versus simplicity, familiarity, and ecosystem maturity. Because this package is described as unproven, compare maintenance and API stability before standardizing on it.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
skyraptor/chatter
edlugz/sasapay
abbasudo/artisan-route
mirvan/ippanel
ignibyte/aic-framework
glavweb/data-schema-bundle
glavweb/datagrid-bundle
tacticmedia/scim-server
uni-method/frame
neika-ai/sdk
adachsoft/php-code-style
pharaonic/laravel-notification-dependencies
beautinow/translug
dev-brainiac/bot-cloaked
octoberrain/html
octoberrain/extension
octoberrain/exception
octoberrain/contracts
adachsoft/api-version-bundle
cgv/localized-resource