PHPackages                             koca/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. koca/easyregex

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

koca/easyregex
==============

PHP Regular expressions made easy

1.0.1(9y ago)11455MITPHPPHP &gt;=5.3

Since Jun 16Pushed 9y ago2 watchersCompare

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

READMEChangelog (1)Dependencies (2)Versions (3)Used By (0)

Easy Regex
----------

[](#easy-regex)

- ported from [VerbalExpressions](https://github.com/VerbalExpressions/PHPVerbalExpressions)

EasyRegex is a PHP library that helps to construct hard regular expressions.

Install
-------

[](#install)

```
$ composer require koca/easyregex

```

Usage
-----

[](#usage)

```
// some tests
use Koca\EasyRegex\EasyRegex;

$regex = new EasyRegex;

$regex  ->startOfLine()
        ->then("http")
        ->maybe("s")
        ->then("://")
        ->maybe("www.")
        ->anythingBut(" ")
        ->endOfLine();

if($regex->test("https://github.com/"))
    echo "valid url";
else
    echo "invalid url";

if (preg_match($regex, 'http://github.com')) {
    echo 'valid url';
} else {
    echo 'invalid url';
}

echo "". $regex->getRegex() ."";

echo $regex ->clean(array("modifiers" => "m", "replaceLimit" => 4))
            ->find(' ')
            ->replace("This is a small test http://somesite.com and some more text.", "-");
```

### Regex Capturing

[](#regex-capturing)

```
$regex->find("You have ")
    ->beginCapture("count")
    ->word()
    ->endCapture();

$contributions = $regex->match("You have 258 contributions in the last year");

echo $contributions["count"];

// Output: 258
```

\##Methods list

NameDescriptionUsageaddadd values to the expressionadd('abc')startOfLinemark expression with ^startOfLine(false)endoOfLinemark the expression with $endOfLine()thenadd a string to the expressionadd('foo')findalias for thenfind('foo')maybedefine a string that might appear once or notmaybe('.com')anythingaccept any stringanything()anythingUntilAnything up until given sequence of charactersanythingUntil('.com')anythingButaccept any string but the specified charanythingBut(',')somethingaccept any non-empty stringsomething()somethingButanything non-empty except for these charssomethingBut('a')replaceshorthand for preg\_replace()replace($source, $val)lineBreakmatch \\r \\nlineBreak()brshorthand for lineBreakbr()tabmatch tabs \\ttab()wordmatch \\w+word()anyOfany of the listed charsanyOf('abc')anyshorthand for anyOfany('abc')rangeadds a range to the expressionrange(a,z,0,9)withAnyCasematch case default case sensitivewithAnyCase()beginCaptureCapture groups (can optionally name)beginCapture("bar")endCaptureStop captureendCapture()matchShorthand method for preg\_matchmatch("long string")matchAllShorthand method for preg\_match\_allmatchAll("long string")stopAtFirsttoggles the g modifiersstopAtFirst()addModifieradd a modifieraddModifier('g')removeModifierremove a mofierremoveModifier('g')searchOneLineToggles m modifiersearchOneLine()multipleadds the multiple modifiermultiple('\*')\_orwraps the expression in an `or` with the provided value\_or('bar')limitadds char limitlimit(1,3)testperforms a preg\_matchtest('')Building the project and running the tests
------------------------------------------

[](#building-the-project-and-running-the-tests)

The project supports Composer so you have to install [Composer](https://getcomposer.org/doc/00-intro.md#installation-nix) first before project setup.

```
curl -sS https://getcomposer.org/installer | php
php composer.phar install --dev
ln -s vendor/phpunit/phpunit/phpunit.php phpunit
./phpunit

```

License
-------

[](#license)

This project is free and open source software, distributed under the [MIT License](/LICENSE)

###  Health Score

29

—

LowBetter than 57% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity17

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity59

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

Every ~26 days

Total

2

Last Release

3640d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/342666?v=4)[Mesut Koca](/maintainers/koca)[@koca](https://github.com/koca)

---

Top Contributors

[![koca](https://avatars.githubusercontent.com/u/342666?v=4)](https://github.com/koca "koca (8 commits)")

---

Tags

phpphp-libraryregexregex

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[composer/pcre

PCRE wrapping library that offers type-safe preg\_\* replacements.

707347.9M55](/packages/composer-pcre)[spatie/regex

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

1.1k18.9M68](/packages/spatie-regex)[gherkins/regexpbuilderphp

PHP port of thebinarysearchtree/regexpbuilderjs

1.3k189.0k1](/packages/gherkins-regexpbuilderphp)[regex-guard/regex-guard

A wrapper that allows you to validate regular expressions and handle normally uncatchable PCRE compilation warnings

24530.3k8](/packages/regex-guard-regex-guard)[kozz/emoji-regex

Emoji regex parser

31174.0k](/packages/kozz-emoji-regex)[hallindavid/manny

a package of manipulators that hopefully come in useful for those of us who always forget regex when we need it (manny is short for manipulation)

37106.7k3](/packages/hallindavid-manny)

PHPackages © 2026

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