https://github.com/ldrahnik/regexp
Keeper of regular expressions.
https://github.com/ldrahnik/regexp
nette package php
Last synced: about 1 month ago
JSON representation
Keeper of regular expressions.
- Host: GitHub
- URL: https://github.com/ldrahnik/regexp
- Owner: ldrahnik
- License: other
- Created: 2015-01-06T12:14:39.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2017-09-17T20:32:15.000Z (almost 9 years ago)
- Last Synced: 2026-04-08T17:43:21.149Z (3 months ago)
- Topics: nette, package, php
- Language: PHP
- Homepage:
- Size: 40 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
ldrahnik/regexp
======
[](https://travis-ci.org/ldrahnik/regexp)
[](https://packagist.org/packages/ldrahnik/regext)
[](https://packagist.org/packages/ldrahnik/regexp)
Set of regular expressions.
Requirements
------------
ldrahnik/regexp requires PHP 5.4 or higher.
- [Nette Framework](https://github.com/nette/nette)
Installation
------------
Install regexp to your project using [Composer](http://getcomposer.org/):
```sh
$ composer require ldrahnik/regexp
```
Usage
-----
Register extension in config file
```sh
extensions:
regexp: regexp\DI\RegexpHelperExtension
regexp:
myRegularName: ^[0-9]{1,10}$
twitterUsername: foo
```
Now you can use all regulars through services
```php
/** @var \regexp\Regexp @inject */
private $regexp;
public function __construct(regexp\Regexp $regexp)
{
$this->regexp = $regexp;
}
public function createComponentForm()
{
$form = new Nette\Application\UI\Form();
$form->addText('twitter', 'Twitter username')
->setDefaultValue('@')
->addCondition(Form::FILLED)
->addRule(Form::PATTERN, 'Please enter twitter username, for example: @username',
$this->regexp->getTwitterUsername());
...
// $this->regexp->getRegularExpression('twitterUsername'));
// equivalent of that expression is
// $this->regexp->getTwitterUsername();
}
....
```
You are able to use or override already existing embedded regular expressions
```sh
'username' => '^[a-z0-9_-]{3,16}$',
'twitterUsername' => '^(\@)?[A-Za-z0-9_]+$',
'password' => '^[a-z0-9_-]{6,18}$',
'facebook' => '^(https?:\/\/)?(www\.)?facebook.com\/[a-zA-Z0-9(\.\?)?]',
'google' => '((http|https):\/\/)?(www[.])?plus\.google\.com\/.?\/?.?\/?([0-9]*)'
```