2017 © Pedro Peláez
 

library range-regex

Returns a regex-compatible range from two numbers, min and max.

image

hansott/range-regex

Returns a regex-compatible range from two numbers, min and max.

  • Tuesday, April 24, 2018
  • by hansott
  • Repository
  • 2 Watchers
  • 1 Stars
  • 12 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

Range Regex

Latest Version on Packagist ![Software License][ico-license] Build Status ![Coverage Status][ico-scrutinizer] Quality Score ![Total Downloads][ico-downloads], (*1)

Returns a regex-compatible range from two numbers, min and max. Inspired by jonschlinkert/to-regex-range., (*2)

Why would I need this?

That's a good question. You normally would write something like if ($x > $min && $x < $max) { ... }, right?, (*3)

Say you want to build a glob like function yourself., (*4)

If your glob would support syntax like foo/{1..5}.md and you plan to do the matching using a regex pattern.. Well, this library can convert 1..5 to a regex., (*5)

Read More, (*6)

Install

Via Composer, (*7)

``` bash $ composer require hansott/range-regex, (*8)


## Usage ``` php use HansOtt\RangeRegex\FactoryDefault; use HansOtt\RangeRegex\Range; $factory = new FactoryDefault(); $converter = $factory->getConverter(); $range = new Range(1, 3456); $regex = sprintf('/^(%s)$/', $converter->toRegex($range)); // /^([1-9]|[1-9][0-9]|[1-9][0-9]{2}|[1-2][0-9]{3}|3[0-3][0-9]{2}|34[0-4][0-9]|345[0-6])$/ $matchesRegex = (bool) preg_match($regex, 0); // false $matchesRegex = (bool) preg_match($regex, 2014); // true $matchesRegex = (bool) preg_match($regex, 3457); // false

Change log

Please see CHANGELOG for more information what has changed recently., (*9)

Testing

bash $ composer test, (*10)

Contributing

Please see CONTRIBUTING and CONDUCT for details., (*11)

Credits

License

The MIT License (MIT). Please see License File for more information., (*12)

The Versions

24/04 2018

dev-master

9999999-dev https://github.com/hansott/range-regex

Returns a regex-compatible range from two numbers, min and max.

  Sources   Download

MIT

The Requires

  • php ~5.5|~7.0

 

The Development Requires

validation range number regex numeric match glob hansott ranges brace expansion

11/07 2016

1.0.0

1.0.0.0 https://github.com/hansott/range-regex

Returns a regex-compatible range from two numbers, min and max.

  Sources   Download

MIT

The Requires

  • php ~5.5|~7.0

 

The Development Requires

validation range number regex numeric match glob hansott ranges brace expansion