PHPackages                             darshphpdev/easyregex - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. darshphpdev/easyregex

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

darshphpdev/easyregex
=====================

Simple Regex Pattern Generator and Validator

v1.0.0(5y ago)77MITPHP

Since Nov 1Pushed 5y ago1 watchersCompare

[ Source](https://github.com/DarshPhpDev/easyregex)[ Packagist](https://packagist.org/packages/darshphpdev/easyregex)[ RSS](/packages/darshphpdev-easyregex/feed)WikiDiscussions master Synced 3w ago

READMEChangelogDependenciesVersions (2)Used By (0)

Laravel EasyRegex Package
=========================

[](#laravel-easyregex-package)

[![Issues](https://camo.githubusercontent.com/8d17293aa9de851e8be44ce711bfbcedc0ab13bb2d7eb87efaa9a914ee344892/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6973737565732f44617273685068704465762f6561737972656765782e7376673f7374796c653d666c61742d737175617265)](https://github.com/DarshPhpDev/easyregex/issues)[![Stars](https://camo.githubusercontent.com/f791e89831c8d0670f599ebb3e3571b20ac3d1236653fb3f89ead5652ef507ee/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f73746172732f44617273685068704465762f6561737972656765782e7376673f7374796c653d666c61742d737175617265)](https://github.com/DarshPhpDev/easyregex/stargazers)[![Downloads](https://camo.githubusercontent.com/88fd3cef37d7c5cccc9a3b30fefd32da03668fac4915adfe168f8c1c8b470141/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f44617273685068704465762f6561737972656765782e7376673f7374796c653d666c61742d737175617265)](https://github.com/DarshPhpDev/easyregex)[![License](https://camo.githubusercontent.com/f3141b8fcf82c5bf1042df892770b7b6fc825ca49deca65d79921a8912323e2a/68747470733a2f2f706f7365722e707567782e6f72672f44617273685068704465762f6561737972656765782f6c6963656e73652e737667)](https://github.com/DarshPhpDev/easyregex)

Simple Regex Pattern Generator and Validator.
---------------------------------------------

[](#simple-regex-pattern-generator-and-validator)

#### Regular expressions are dense. This makes them hard to read, but not in proportion to the information they carry. It has a very terse syntax and if you make even the smallest mistake it won’t perform as expected.

[](#regular-expressions-are-dense-this-makes-them-hard-to-read-but-not-in-proportion-to-the-information-they-carry-it-has-a-very-terse-syntax-and-if-you-make-even-the-smallest-mistake-it-wont-perform-as-expected)

#### It's Ok. Writing regular expressions will not be your biggest fears any more!

[](#its-ok-writing-regular-expressions-will-not-be-your-biggest-fears-any-more)

INSTALLATION
------------

[](#installation)

Install the package through [Composer](http://getcomposer.org/).

`composer require darshphpdev/easyregex`

CONFIGURATION
-------------

[](#configuration)

Optional: The service provider will automatically get registered. Or you may manually add the service provider to providers array in your config/app.php file:

```
'providers' => [
    // ...
    DarshPhpDev\EasyRegex\\EasyRegexServiceProvider::class,
];
```

HOW TO USE
----------

[](#how-to-use)

- [Quick Usage](#quick)
- [Usage](#usage)
- [Examples](#examples)
- [Credits](#credits)
- [License](#license)

Quick Usage
-----------

[](#quick-usage)

```
// In your controller
// Use The Helper class RegexBuilder to build and validate regex
use RegexBuilder;

$regex = RegexBuilder::make()->startsWith()->literally('abc')
					->anyLetterOf('A', 'B', 'C')
					->zeroOrMore()
			    		->where(function ($query) {
					        $query->digit()->smallLetter();
					    })->toRegexString();
// the above example will return the regex string /^abc[ABC]*([0-9][a-z])/

// you can also match your string against the generated regex
$regexObject = RegexBuilder::make()->startsWith()->literally('abc')
					->anyLetterOf('A', 'B', 'C')
					->zeroOrMore()
			    		->where(function ($query) {
					        $query->digit()->smallLetter();
					    });
$isMatching = $regexObject->match('abcAAA5g');		// $isMatching = true
$isMatching = $regexObject->match('abdd5g');		// $isMatching = false

// you can also specify the wrapping symbol as an argument to the make() function
// default is '/'
$regex = RegexBuilder::make('#')->literally('a')
				->letterPatternOf('ABC')
				->zeroOrMore()
	    			->toRegexString();
// the above example will return the regex string #a(ABC)*#

// you can also use the global helper regexBuilder()
$regex = regexBuilder()->make()->digit()
			->capitalLetters('A', 'F')
			->onceOrMore()
			->toRegexString();
// the above example will return the regex string /[0-9][A-F]+/
// FOR FULL USAGE, SEE BELOW..
```

Usage
-----

[](#usage)

### Table Of Helper Regex Functions

[](#table-of-helper-regex-functions)

Use the following function to build your regex string.

FunctionDescriptionArgumentsmake()Initialize the builder object, set the default wrapper delimiter /$delimiter (Optional)startsWith()Inserts the start with regex symbol-onceOrMore()Repeat the preceding letter/pattern once or more-zeroOrMore()Repeat the preceding letter/pattern zero times or more-anyChar()Matches any character or digit including special ones.-tab()Matches tab-newLine()Matches new line-whitespace()Matches white space-anyWord()Matches any word (letters or digits)-literally()Matches any single letter or set of letters or pattern including special chars and meta chars$str (Required)anyLetterOf()Matches one letter of the given single or multiple parameters$letters (Required)exceptLetterOf()Ignores one letter of the given single or multiple parameters$letters (Required)letterPatternOf()Matches the whole letter set with the given sorting.$letters (Required)exceptPatternOf()Matches any thing except for the whole letter set with the given sorting.$letters (Required)digit()Matches any digit- $min (Optional) default\[0\] - $max (Optional) default\[9\]notDigit()Matches any thing except any digit- $min (Optional) default\[0\] - $max (Optional) default\[9\]atLeast()Matches Repeating the preceding pattern at least $number of times$number (Required)atMost()Matches Repeating the preceding pattern at most $number of times$number (Required)smallLetter()Matches any small letter between $min and $max letters- $min (Optional) default\[a\] - $max (Optional) default\[z\]exceptSmallLetters()Matches any small letter except those between $min and $max letters- $min (Optional) default\[a\] - $max (Optional) default\[z\]capitalLetters()Matches any capital letter between $min and $max letters- $min (Optional) default\[A\] - $max (Optional) default\[Z\]exceptCapitalLetters()Matches any capital letter except those between $min and $max letters- $min (Optional) default\[A\] - $max (Optional) default\[Z\]optional()Make the preceding pattern optional-rawRegex()Add raw regex string$rawStringwhere()Group set of regex expressionsClosure function(){}toRegexString()Return the final Regex string.-match()Validate your $input against the generated regex string$input (Required)Examples
--------

[](#examples)

### More examples!

[](#more-examples)

```
$regex = RegexBuilder::make()->literally('Regex')->toRegexString();
// $regex = /Regex/
$regex = RegexBuilder::make()->anyLetterOf('a', 'b', 'c')->toRegexString();
// $regex = /[abc]/
$regex = RegexBuilder::make()->exceptLetterOf('c')->toRegexString();
// $regex = /[^c]/
$regex = RegexBuilder::make()->letterPatternOf('july')->toRegexString();
// $regex = /(july)/
$regex = RegexBuilder::make()->digit()->anyChar()->toRegexString();
// $regex = /[0-9]./
$regex = RegexBuilder::make()->anyChar()->atMost(5)->toRegexString();
// $regex = /.{5}/
$regex = RegexBuilder::make()->exceptSmallLetters('u', 'z')->toRegexString();
// $regex = /[^u-z]/
$regex = RegexBuilder::make()->capitalLetters('A', 'F')->toRegexString();
// $regex = /[A-F]/
$regex = RegexBuilder::make()->rawRegex('a(ABC)*')->match('aABCABCABC');
// $regex = true
$regex = RegexBuilder::make()->rawRegex('a(ABC)*')->match('aABCABCA');
// $regex = false

// and so on..
```

### Any suggestions or enhancements are very welcomed.

[](#any-suggestions-or-enhancements-are-very-welcomed)

Credits
-------

[](#credits)

- [MUSTAFA AHMED](https://github.com/DarshPhpDev)

License
-------

[](#license)

The EasyRegex Package is open-sourced software licensed under the [MIT license](http://opensource.org/licenses/MIT)

###  Health Score

25

—

LowBetter than 36% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity54

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

2060d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/5dc427456706f88e785b5ded5d2e9673e9bc7fa8a742b5949a62db0272de5181?d=identicon)[DarshPhpDev](/maintainers/DarshPhpDev)

---

Top Contributors

[![mustafashifters](https://avatars.githubusercontent.com/u/112804225?v=4)](https://github.com/mustafashifters "mustafashifters (1 commits)")

---

Tags

phplaravelexpressionregexregularphpregexregularexpression

### Embed Badge

![Health badge](/badges/darshphpdev-easyregex/health.svg)

```
[![Health](https://phpackages.com/badges/darshphpdev-easyregex/health.svg)](https://phpackages.com/packages/darshphpdev-easyregex)
```

###  Alternatives

[spatie/regex

A sane interface for php's built in preg\_\* functions

1.1k18.9M68](/packages/spatie-regex)[selvinortiz/flux

Fluent regular expressions in PHP.

3372.1k3](/packages/selvinortiz-flux)[amranidev/laracombee

Recommendation system for laravel

11537.9k1](/packages/amranidev-laracombee)[yieldstudio/tailwind-merge-php

Merge Tailwind CSS classes without style conflicts

4974.6k1](/packages/yieldstudio-tailwind-merge-php)[wujunze/money-wrapper

MoneyPHP Wrapper

103.8k](/packages/wujunze-money-wrapper)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
