Simple, customizable regex builder focused on letters and numbers.
composer require DePlaced/regex-simplifieduse DePlaced\RegexSimplified\Regex;
// Example: match uppercase-only strings
$rx = Regex::make()
->start()
->uppercase()
->oneOrMore()
->end();
var_dump($rx->test('HELLO')); // true
var_dump($rx->test('Hello')); // false| Pattern | Chain | Matches | Non-matches |
|---|---|---|---|
/^[a-z]+$/u |
Regex::make()->start()->lowercase()->oneOrMore()->end() |
abc, hello |
Hello, 123 |
/^[A-Z]+$/u |
Regex::make()->start()->uppercase()->oneOrMore()->end() |
ABC, HELLO |
Hello, abc |
/^[A-Za-z]{3,5}$/u |
Regex::make()->start()->letter()->repeat(3,5)->end() |
abc, Hello |
he, toolong |
| Method | Description |
|---|---|
Regex::make() |
Create a new instance. |
lowercase() |
Match lowercase letters [a-z]. |
uppercase() |
Match uppercase letters [A-Z]. |
letter() |
Match any letter [A-Za-z]. |
number() |
Match digits [0-9]. |
oneOrMore() |
Quantifier +. |
repeat($min, $max = null) |
Quantifier {min,max}. |
start() |
Anchor to start ^. |
end() |
Anchor to end $. |
toPreg() |
Get the final regex string. |
test($string) |
Test a string against the built regex. |
Clone your fork and install dependencies:
composer installRun tests:
vendor/bin/phpunitThis project follows Semantic Versioning.
- Before
1.0.0, breaking changes may occur in minor versions (0.x.0). - After
1.0.0, breaking changes only happen in major versions.
See CHANGELOG.md for release notes.
Pull requests and issues are welcome!
Please use Conventional Commits if possible:
feat:new featurefix:bug fixdocs:documentationtest:testschore:maintenance
This project is open source under the MIT License.