Download the PHP package gobie/regex without Composer

On this page you can find all versions of the php package gobie/regex. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package regex

Regex

Build Status Code Coverage Latest Stable Version Total Downloads Scrutinizer Quality Score SensioLabsInsight

Regex is PHP library containing lightweight wrappers around regular expression libraries and extensions for day to day use. We try to resolve error related issues those libraries expose and which they handle rather peculiarly. We also gave a shot at unifying API they provide so library is meant to be drop-in replacement for their existing counterparts for most of the usages.

Currently the most popular regular expression library is PCRE with its preg_* functions. Mbstring extension with its mb_ereg_* functions as an optional extension is not available everywhere. POSIX Extended implementation with its ereg_* functions is deprecated as of PHP 5.3.0 and should not be used.

Regex library implements wrappers for

Installation

Download and install composer from http://www.getcomposer.org/download

Add the following to your project composer.json file

When you're done just run php composer.phar install and the package is ready to be used.

Unified API

Regular expression libraries provide variety of functions, but they are not replaceable out of the box. So we tried to unify API across those libraries. There are several methods implemented with basic signature in all wrappers. Pattern signature is different in each driver as PCRE is Perl-like and mbstring can change it on the fly with options.

Driver can add another arguments to signature or handle more types.

For instance PcreRegex::get() adds $flags and $offset arguments to create signature PcreRegex::get($pattern, $subject, $flags, $offset), but the basic arguments remain the same.

To accomplish this API, some methods had to be created in userland code.

For instance mbstring doesn't have corresponding functions for PCRE functions preg_match_all(), preg_grep() or preg_filter(), thus methods like MbRegex::getAll(), MbRegex::grep() and MbRegex::filter() had to be created from scratch using mbstring primitives.

Examples

This library solves error handling problems by doing all the heavy lifting in reusable manner. Every error is handled by exception derived from \Gobie\Regex\RegexException.

Once again quite readable with all the error handling you need.

Requirements

PHP 5.3.3 or above. Unit tests are regularly run against latest 5.3, 5.4, 5.5 and HHVM. For mb_ereg_replace_callback() and thus for usage of MbRegex::replace() PHP 5.4 and above is required.

Note on HHVM

Functions preg_filter() and mb_ereg_replace_callback() are not to date supported. Some error messages have different format, mostly just added pattern which causes unit test error. Backtracking and recursion error messages are completely different and much more descriptive. You can find out about these differences in unit test reports on travis-ci.

FAQ

Why should I care? / What problem does it solve?

Regular expression libraries provide us with set of functions we have to deal with. They are somewhat similar and yet each slightly different in covered functionality and error handling.

Take for instance PCRE library. Common code seen in applications is

This code is correct as long as $pattern is not dynamically created and matching can never hit backtracking or recursion limit and $subject as well as $pattern are well formed UTF-8 strings (if UTF-8 is used).

Two types of errors can happen here. We speak about compilation errors which trigger E_WARNING like input errors. And runtime errors like hitting backtracking or recursion limit or encoding issues. We can deal with those using preg_last_error() function. But only if compilation error didn't happen, otherwise this function is unreliable as it doesn't clear its state.

More robust and less error-prone version:

That's a lot of error handling to take care about, but it gets even more complicated.

For instance using preg_replace_callback() naively can make your life harder and put your debugging skills to test. Usually, you use it the simplest way:

Lots can happen here, compilation and runtime errors shown above and also errors triggered from within $callback. We just can't cover it with error handler like above, since errors from within callback should not be caught by regex error handling. So the correct solution, which would catch compilation and runtime errors, but let the rest come through, could look like this:

Not to mention handling more complex cases like array of patterns.

Why is it implemented via static methods instead of nice object oriented way we all use and love?

It is meant to be used as drop-in replacement for current usage of library/extension functions.

I want to use it as dependency in object oriented style, can I?

No problem, for that case we have RegexFacade which just redirects object calls to given wrapper.

I don't want to use exceptions to handle regex errors. What can I do?

Wrappers are prepared to be extended to overwrite anything the way you want. For instance triggering errors instead of throwing exceptions can be implemented this way:

I just want to use unified API without the error handling.

Wrappers are easily extensible to accommodate any request.

Performance

Performance is one of the main reasons we try to avoid regular expressions as much as possible. It is much more efficient to use string function like strpos, substr, str_replace, explode, etc if possible.

But there are times we need regular expressions. So we did a little benchmarking to show you, what does our abstraction take out of performance of using native functions. We think that added functionality and usable error handling quite compensates the lost performance but decide for yourself.

MbBench is missing some native function benchmarks as they don't have native implementation.

StringBench was added for comparison. It could accomplish roughly the same tasks in testing scenarios.

You can run the benchmark yourself

Contribute

Contributions are always welcome as well as any questions or issues.

Unit and integration testing is done via phpunit with configuration file tests/complete.phpunit.xml.


All versions of regex with dependencies

PHP Build Version
Package Version
Requires php Version >=5.3.2
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package gobie/regex contains the following files

Loading the files please wait ....