PHPackages                             dixflatlinr/preg\_return - 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. dixflatlinr/preg\_return

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

dixflatlinr/preg\_return
========================

Preg\_match that returns the result(s) of your choice.

1.0.2(1mo ago)0571BSD-3-ClausePHPPHP &gt;=7.4.0

Since Feb 9Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/dixflatlinr/preg_return)[ Packagist](https://packagist.org/packages/dixflatlinr/preg_return)[ Docs](https://github.com/dixflatlinr/preg_return)[ RSS](/packages/dixflatlinr-preg-return/feed)WikiDiscussions main Synced yesterday

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

preg\_return
============

[](#preg_return)

~ is a convenience PHP library which provides an alternate way to use preg\_match. Works like preg\_match, but returns the matching elements or a subset.

Installation
============

[](#installation)

The recommended way to install **preg\_return** is through [Composer](https://getcomposer.org/).

```
composer require dixflatlinr/preg_return
```

Syntax &amp; usage
------------------

[](#syntax--usage)

The package registers global functions as a convenience, so it can be used such:

```
preg_return(string $pattern, string $subject, $indexesToReturn = null, int $flags = 0, int $offset = 0)
preg_return_all(string $pattern, string $subject, $indexesToReturn = null, int $flags = 0, int $offset = 0)
preg_return_replace(string $pattern, string $replacement, string &$subject, $indexesToReturn = null, int $flags = 0, int $offset = 0)
```

Or calling it directly:

```
RX::pregReturn(string $pattern, string $subject, $indexesToReturn = null, int $flags = 0, int $offset = 0)
RX::pregReturnAll(string $pattern, string $subject, $indexesToReturn = null, int $flags = 0, int $offset = 0)
RX::pregReturnReplace(string $pattern, string $replacement, string &$subject, $indexesToReturn = null, int $flags = 0, int $offset = 0)
```

The only difference compared to

```
preg_match(string $pattern, string $subject, array &$matches = null, int $flags = 0, int $offset = 0): int|false
```

is that instead of the `&$matches` parameter, now `$indexesToReturn` governs what is returned and how.

Examples
--------

[](#examples)

```
