PHPackages                             shopbase/regex - 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. shopbase/regex

Abandoned → [https://github.com/flexicsystems/regex](/?search=https%3A%2F%2Fgithub.com%2Fflexicsystems%2Fregex)ArchivedLibrary[Utility &amp; Helpers](/categories/utility)

shopbase/regex
==============

This is a package which allows PHP Regex usage without much setup. You can use the static functions as like as the default preg\_\* functions and they will give you a match object with a lot of functions to evaluate the matches.

1.1.0.0(7y ago)02MITPHPPHP ^7.1.3

Since Jan 11Pushed 3y agoCompare

[ Source](https://github.com/ThemePoint/Regex)[ Packagist](https://packagist.org/packages/shopbase/regex)[ Docs](https://www.themepoint.de)[ RSS](/packages/shopbase-regex/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (2)DependenciesVersions (3)Used By (0)

! Package is not maintained anymore. Please use [`flexic/regex`](https://github.com/flexicsystems/regex) in future.
-------------------------------------------------------------------------------------------------------------------

[](#-package-is-not-maintained-anymore-please-use-flexicregex-in-future)

Regex
=====

[](#regex)

This is a package which allows PHP Regex usage without much setup. You can use the static functions as like as the default preg\_\* functions and they will give you a match object with a lot of functions to evaluate the matches.

Copyright (c) 2019 Shopbase

Usage
=====

[](#usage)

There are several functions which you can use.

```
// preg_match
$result = \Shopbase\Regex\Regex::match('/(foo)(bar)(baz)/', 'foobarbaz');

// preg_match_all
$result = \Shopbase\Regex\Regex::matchAll('/(?J)(?foo)|(?bar)/', 'foo bar');

// preg_replace
$result = \Shopbase\Regex\Regex::replace('/(\d+)\. (\w+) (\d+)/i', '15. April 2003', '${2}1,$3');

// preg_split
$result = \Shopbase\Regex\Regex::split('/[\s,]+/', 'hypertext language, programming');

// preg_grep
$result = \Shopbase\Regex\Regex::grep('/^(\d+)?\.\d+$/', array(0,1,0.5,1.5));

// preg_filter
$result = \Shopbase\Regex\Regex::filter(array('/\d/', '/[a-z]/', '/[1a]/'), array('A:$0', 'B:$0', 'C:$0'), array('1', 'a', '2', 'b', '3', 'A', 'B', '4'));

// preg_quote. This function will validate you expression and return it as string.
\Shopbase\Regex\Regex::validateExpression('...');
\Shopbase\Regex\Regex::quote('...');
```

All of these functions will return an object of type '\\Shopbase\\Regex\\Result\\Result'. This object contains the matches and several informations about them.

```
// get the boolean status if the result contains matches or not.
$result = \Shopbase\Regex\Regex::match('/(foo)(bar)(baz)/', 'foobarbaz')->getHasMatches();

// get the count of contained matches
$result = \Shopbase\Regex\Regex::match('/(foo)(bar)(baz)/', 'foobarbaz')->getCount();

// get the '\Shopbase\Regex\Result\Matches' object. This object contains all found matches.
$result = \Shopbase\Regex\Regex::match('/(foo)(bar)(baz)/', 'foobarbaz')->getMatches();
```

If you use the 'getMatches' function of Result object you will get an object which contains all matches and a list of functions to handle them.

```
// get array with all matches
$result = \Shopbase\Regex\Regex::match('/(foo)(bar)(baz)/', 'foobarbaz')->getMatches()->matches();

// get a group by int. Here it is possible to include subgroups (Every array item will represent an group into an group)
$result = \Shopbase\Regex\Regex::match('/(foo)(bar)(baz)/', 'foobarbaz')->getMatches()->group(0);
$result = \Shopbase\Regex\Regex::match('/(foo)(bar)(baz)/', 'foobarbaz')->getMatches()->group(0, [0, 0]);

// you can do the same group function with string values. It will work equal as the 'group' function
$result = \Shopbase\Regex\Regex::match('/(foo)(bar)(baz)/', 'foobarbaz')->getMatches()->namedGroup('group');
$result = \Shopbase\Regex\Regex::match('/(foo)(bar)(baz)/', 'foobarbaz')->getMatches()->namedGroup('group', ['subgroup', 'subgroup']);

// to get multiple groups you can use the 'groups' function. Here it is possible to include the subgroups of every item, too.
$result = \Shopbase\Regex\Regex::match('/(foo)(bar)(baz)/', 'foobarbaz')->getMatches()->groups(0, 1, 2);
$result = \Shopbase\Regex\Regex::match('/(foo)(bar)(baz)/', 'foobarbaz')->getMatches()->groups([0, 0], [1, 0], 2);

$result = \Shopbase\Regex\Regex::match('/(foo)(bar)(baz)/', 'foobarbaz')->getMatches()->namedGroups('group_1', 'group_2', 'group_3');
$result = \Shopbase\Regex\Regex::match('/(foo)(bar)(baz)/', 'foobarbaz')->getMatches()->namedGroups(['group_1', 'subgroup_1'], ['group_2', 'subgroup_1', 'subgroup_2'], 'group_3');

// map matches by callback function
$result = \Shopbase\Regex\Regex::match('/(foo)(bar)(baz)/', 'foobarbaz')->getMatches()->map(function ($item){...});

// merge matches to string
$result = \Shopbase\Regex\Regex::match('/(foo)(bar)(baz)/', 'foobarbaz')->getMatches()->merge();

// get count of matches
$result = \Shopbase\Regex\Regex::match('/(foo)(bar)(baz)/', 'foobarbaz')->getMatches()->count();
```

The regex function will accept several flags. This flags will contained into the following object.

```
\Shopbase\Regex\RegexFlags::$PREG_OFFSET_CAPTURE;
\Shopbase\Regex\RegexFlags::$PREG_UNMATCHED_AS_NULL;
\Shopbase\Regex\RegexFlags::$PREG_PATTERN_ORDER;
\Shopbase\Regex\RegexFlags::$PREG_SET_ORDER;
\Shopbase\Regex\RegexFlags::$PREG_GREP_INVERT;
\Shopbase\Regex\RegexFlags::$PREG_SPLIT_NO_EMPTY;
\Shopbase\Regex\RegexFlags::$PREG_SPLIT_DELIM_CAPTURE;
\Shopbase\Regex\RegexFlags::$PREG_SPLIT_OFFSET_CAPTURE;
```

Patterns
========

[](#patterns)

The package contains a object which includes some predefined patterns

```
\Shopbase\Regex\RegexPattern::getHtmlSearchExpression('div');
```

[![Donate](https://camo.githubusercontent.com/b57c445af971e3e99c2d0ccdbf4fa7faa4358ba27fecc8f68459b30289f82eda/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f446f6e6174652d50617950616c2d626c75652e737667)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=Q98R2QXXMTUF6&source=url)

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity2

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity57

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 ~1 days

Total

2

Last Release

2678d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/bee461f8192dd9177138458bcf9558257c572316ca6fed26b68d2f1e7efbb5be?d=identicon)[ThemePoint](/maintainers/ThemePoint)

---

Top Contributors

[![ThemePoint](https://avatars.githubusercontent.com/u/28843201?v=4)](https://github.com/ThemePoint "ThemePoint (14 commits)")

---

Tags

phpregexpatternmatching

### Embed Badge

![Health badge](/badges/shopbase-regex/health.svg)

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

###  Alternatives

[gherkins/regexpbuilderphp

PHP port of thebinarysearchtree/regexpbuilderjs

1.4k163.0k1](/packages/gherkins-regexpbuilderphp)[selvinortiz/flux

Fluent regular expressions in PHP.

3372.0k1](/packages/selvinortiz-flux)[rolfvreijdenberger/izzum-statemachine

A superior statemachine library php &gt;= 5.3. Integrates with your domain models perfectly.

7425.5k](/packages/rolfvreijdenberger-izzum-statemachine)

PHPackages © 2026

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