PHPackages                             hansott/range-regex - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Validation &amp; Sanitization](/categories/validation)
4. /
5. hansott/range-regex

AbandonedArchivedLibrary[Validation &amp; Sanitization](/categories/validation)

hansott/range-regex
===================

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

1.0.0(9y ago)32681MITPHPPHP ~5.5|~7.0

Since Jul 11Pushed 8y ago1 watchersCompare

[ Source](https://github.com/hansott/range-regex)[ Packagist](https://packagist.org/packages/hansott/range-regex)[ Docs](https://github.com/hansott/range-regex)[ RSS](/packages/hansott-range-regex/feed)WikiDiscussions master Synced today

READMEChangelog (1)Dependencies (3)Versions (2)Used By (1)

Range Regex
===========

[](#range-regex)

[![Latest Version on Packagist](https://camo.githubusercontent.com/24196e519761ddf89c6202064405780ad6ee2ce54c514855225ad74a7186a9e6/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f68616e736f74742f72616e67652d72656765782e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/hansott/range-regex)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Build Status](https://camo.githubusercontent.com/c63f9a0a0a360afaa1250d0e124438886df449e731aef5ad1775360f7d66a271/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f68616e736f74742f72616e67652d72656765782f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/hansott/range-regex)[![Coverage Status](https://camo.githubusercontent.com/67dd8adf1889dc6a406915839969680bcaa3928d94840f151d62fc33f97a2a9e/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f68616e736f74742f72616e67652d72656765782e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/hansott/range-regex/code-structure)[![Quality Score](https://camo.githubusercontent.com/e9873a4a196e5ff889a13f5caeb3b9be8062cdb4d96edc68f6b24c73814b2a22/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f68616e736f74742f72616e67652d72656765782e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/hansott/range-regex)[![Total Downloads](https://camo.githubusercontent.com/4f51d7af22be4a4f16737c164107f28486103ac49b66d996ab5db67e09b44ab3/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f68616e736f74742f72616e67652d72656765782e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/hansott/range-regex)

Returns a regex-compatible range from two numbers, min and max. Inspired by [jonschlinkert/to-regex-range](https://github.com/jonschlinkert/to-regex-range).

Why would I need this?
----------------------

[](#why-would-i-need-this)

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

Say you want to build a [glob](https://secure.php.net/manual/en/function.glob.php) like function yourself.

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.

[Read More](https://github.com/micromatch/to-regex-range#convenience)

Install
-------

[](#install)

Via Composer

```
$ composer require hansott/range-regex
```

Usage
-----

[](#usage)

```
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
----------

[](#change-log)

Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.

Testing
-------

[](#testing)

```
$ composer test
```

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) and [CONDUCT](CONDUCT.md) for details.

Credits
-------

[](#credits)

- [Hans Ott](https://github.com/hansott)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

28

—

LowBetter than 52% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity15

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

3641d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/3886384?v=4)[Hans Ott](/maintainers/hansott)[@hansott](https://github.com/hansott)

---

Top Contributors

[![hansott](https://avatars.githubusercontent.com/u/3886384?v=4)](https://github.com/hansott "hansott (13 commits)")

---

Tags

phprangeregexregex-rangevalidationregexglobMatchnumbernumericrangehansottexpansionbraceranges

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/hansott-range-regex/health.svg)

```
[![Health](https://phpackages.com/badges/hansott-range-regex/health.svg)](https://phpackages.com/packages/hansott-range-regex)
```

###  Alternatives

[composer/semver

Version comparison library that offers utilities, version constraint parsing and validation.

3.3k510.9M901](/packages/composer-semver)[giggsey/libphonenumber-for-php

A library for parsing, formatting, storing and validating international phone numbers, a PHP Port of Google's libphonenumber.

5.0k156.0M488](/packages/giggsey-libphonenumber-for-php)[respect/validation

The most awesome validation engine ever created for PHP

6.0k39.0M408](/packages/respect-validation)[propaganistas/laravel-phone

Adds phone number functionality to Laravel based on Google's libphonenumber API.

3.0k38.3M139](/packages/propaganistas-laravel-phone)[opis/json-schema

Json Schema Validator for PHP

65141.2M263](/packages/opis-json-schema)[giggsey/libphonenumber-for-php-lite

A lite version of giggsey/libphonenumber-for-php, which is a PHP Port of Google's libphonenumber

9315.3M63](/packages/giggsey-libphonenumber-for-php-lite)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
