Download the PHP package simpleregex/srl-php without Composer

On this page you can find all versions of the php package simpleregex/srl-php. 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 srl-php

Simple Regex Language

codecov Build Status License

We all know Regular Expressions are hard to read. Once written you're happy if you never ever have to touch this line of code again because you're going to have a hard time understanding what you've written there.

Before we get started, a short note on how to use SRL: You can either use this project directly, or, if you're not into PHP or including a library like that, you can build your query online and use the generated Regular Expression elsewhere:

https://simple-regex.com/build

An Example

Regular Expressions don't have to be bulky? - No, they don't! Just have a look at this:

Or, if you like, a implementation in code itself:

Yes, indeed, both examples are definitely longer than the corresponding regular expression:

But, however, the above is quite better to read and definitely better to maintain, isn't it? And to top that off: It's much harder to forget to escape something like a dot in SRL.

Let's go through it real quick:

  1. First, we require the matching string to start. This way, we make sure the match won't begin in the middle of something.
  2. Now, we're matching either a digit, a letter, or one of the literal characters ., _, %, + or -. We expect there to be one or more of them.
  3. We now expect exactly one @ - Looks like an email address.
  4. Again, either digits, letters or . or -, once or multiple times.
  5. A dot. Seems to be the end of the TLDs name
  6. To the end, we'll expect two or more letters, for the TLD.
  7. We require the string to end now, to avoid matching stuff like [email protected].
  8. And of course, all of that should be case insensitive, since it's an email address.

Features

Using the Language

Above you can see two examples. The first one uses the language itself, the second one the Query Builder. Since using a language is more fluent than a builder, we wanted to make things as easy as possible for you.

Everything below applies to both, the SRL itself and the Query Builder.

Matching

SRL is as simple as the example above states. To retrieve the built Regular Expression which can be used by external tools like preg_match, either use the ->get() method, or just let it cast to a string:

Of course, you may use the builtin match methods for an even easier approach:

Capture Groups

Since regular expressions aren't only used for validation, capturing groups is supported by SRL as well. After defining the Regular Expression just like before, simply add a capture-group which will match the query defined in the lambda function. Optionally, a name for that capture group (color) can be set as well:

Each match will be passed to a SRL\Match object, which will return the matches found.

Additional PCRE functions

Feel free to use all the available PCRE PHP functions in combination with SRL. Although, why bother? We've got wrappers for all common functions with additional features. Just like above, just apply one of the following methods directly on the SRL or Builder:

Lookarounds

In case you want some regular expressions to only apply in certain conditions, lookarounds are probably what you're searching for.

With queries like:

you can easily capture 'foo', but only if this match is followed by 'bar'.

But to be honest, the Query Builder version is quite much code for such a simple thing, right? No problem! Not only are we supporting anonymous functions for sub-expressions, strings and Builder objects are supported as well. Isn't that great? Just have a look at one possible example:

If desired, lookbehinds are possible as well. Using ifAlreadyHad() you can validate a certain condition only if the previous string contained a specific pattern.

Performance

The built Regular Expression will be cached, so you don't have to worry about it being created every time you call the match-method. And, since it's a normal Regular Expression under the hood, performance won't be an issue.

Of course, building the expression may take some time, but in real life applications this shouldn't be noticeable. But if you like, you can build the expression somewhere else and just use the result in your app. If you do that, please keep the code for that query somewhere and link to it, otherwise the Regular Expression will be unreadable just as before.

Usage

Add the package to your require section in the composer.json-file and update your project.

Things to do

We're definitely not done yet. There's much to come. A short list of stuff that's planned would contain:

License

SRL is published under the MIT license. See LICENSE for more information.

Contribution

Like this project? Want to contribute? Awesome! Feel free to open some pull requests or just open an issue.


All versions of srl-php with dependencies

PHP Build Version
Package Version
Requires php Version >=7.0.0
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 simpleregex/srl-php contains the following files

Loading the files please wait ....