Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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 (about 10 years ago)
- Default Branch: master
- Last Pushed: 2017-09-17T20:32:15.000Z (over 7 years ago)
- Last Synced: 2024-11-14T18:02:18.461Z (2 months ago)
- Topics: nette, package, php
- Language: PHP
- Homepage:
- Size: 40 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
ldrahnik/regexp
======[![Build Status](https://travis-ci.org/ldrahnik/regexp.svg)](https://travis-ci.org/ldrahnik/regexp)
[![Latest stable](https://img.shields.io/packagist/v/ldrahnik/regexp.svg)](https://packagist.org/packages/ldrahnik/regext)
[![Downloads total](https://img.shields.io/packagist/dt/ldrahnik/regexp.svg?style=flat-square)](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\RegexpHelperExtensionregexp:
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]*)'
```