PHPackages                             switchcat/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. switchcat/range-regex

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

switchcat/range-regex
=====================

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

v1.0.1(5y ago)010MITHTMLPHP &gt;=7.4

Since Nov 14Pushed 5y ago1 watchersCompare

[ Source](https://github.com/SwitchCat/range-regex)[ Packagist](https://packagist.org/packages/switchcat/range-regex)[ Docs](https://github.com/switchcat/range-regex)[ RSS](/packages/switchcat-range-regex/feed)WikiDiscussions switchcat Synced 4d ago

READMEChangelog (2)DependenciesVersions (3)Used By (0)

[![Twitter Follow](https://camo.githubusercontent.com/8f03a95e3a1824bccb9b611ed38015dbb2e4437f117150cf02c839bb08a299e5/68747470733a2f2f696d672e736869656c64732e696f2f747769747465722f666f6c6c6f772f537769746368636174413f7374796c653d736f6369616c)](https://twitter.com/SwitchcatA)[![Issues](https://camo.githubusercontent.com/5eb1c29698ce3a2f1622104000822647b4686838f8fc78e9d5719d020a90ae7b/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6973737565732f5377697463684361742f72616e67652d72656765782e7376673f7374796c653d666c61742d737175617265)](https://github.com/SwitchCat/range-regex/issues)[![GitHub All Releases](https://camo.githubusercontent.com/fe39109007af4456b782c472bcdc031d1f536a3851ff124e5ad15e6396c41926/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f646f776e6c6f6164732f5377697463684361742f72616e67652d72656765782f746f74616c3f6c6f676f3d476974487562)](https://camo.githubusercontent.com/fe39109007af4456b782c472bcdc031d1f536a3851ff124e5ad15e6396c41926/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f646f776e6c6f6164732f5377697463684361742f72616e67652d72656765782f746f74616c3f6c6f676f3d476974487562)[![License: MIT](https://camo.githubusercontent.com/fdf2982b9f5d7489dcf44570e714e3a15fce6253e0cc6b5aa61a075aac2ff71b/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d79656c6c6f772e737667)](https://opensource.org/licenses/MIT)[![Codacy Badge](https://camo.githubusercontent.com/d3297f440cfd5d5e3e9c550c1bf49a13d8f939ac39425122db0691f9741a7e79/68747470733a2f2f6170692e636f646163792e636f6d2f70726f6a6563742f62616467652f47726164652f3733643435616366643565383434353239333964353063346436313736383066)](https://app.codacy.com/gh/SwitchCat/range-regex?utm_source=github.com&utm_medium=referral&utm_content=SwitchCat/range-regex&utm_campaign=Badge_Grade)[![](https://camo.githubusercontent.com/17c7ac55bf11c605c135598a2da28bf06dee477f3108f6c4ec10cb147cdda8ae/68747470733a2f2f696d672e736869656c64732e696f2f7374617469632f76313f6c6162656c3d537769746368436174266d6573736167653d4672616d65776f726b26636f6c6f723d666637373031267374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/17c7ac55bf11c605c135598a2da28bf06dee477f3108f6c4ec10cb147cdda8ae/68747470733a2f2f696d672e736869656c64732e696f2f7374617469632f76313f6c6162656c3d537769746368436174266d6573736167653d4672616d65776f726b26636f6c6f723d666637373031267374796c653d666c61742d737175617265)

SwitchCat/range-regex
=====================

[](#switchcatrange-regex)

Table of Contents
-----------------

[](#table-of-contents)

- [Getting Started](#getting-started)
    - [Prerequisites](#prerequisites)
    - [Installation](#installation)
- [Usage](#usage)
- [Contributing](#contributing)
- [License](#license)
- [Contact](#contact)
- [Acknowledgements](#acknowledgements)

Getting Started
---------------

[](#getting-started)

To get a local copy up and running follow these simple steps.

### Prerequisites

[](#prerequisites)

- PHP7.4+
- ext-mbstring
- [Composer](https://getcomposer.org/)

### Installation

[](#installation)

Use composer from the root of your project folder to download the library.

```
composer require switchcat/range-regex
```

Usage
-----

[](#usage)

All method return an array containing either the element's data either an array of elements with their data.

- Create the periodic object

```
use SwitchCat\RangeRegex\FactoryDefault;
use SwitchCat\RangeRegex\Range;

$Factory = new FactoryDefault();
$converter = $Factory->getConverter();
$Range = new Range(int $min, int $max);

$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])$/
```

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

[](#contributing)

Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are **greatly appreciated**.

1. Fork the Project
2. Create your Feature Branch (`git checkout -b feature/AmazingFeature`)
3. Commit your Changes (`git commit -m 'Add some AmazingFeature'`)
4. Push to the Branch (`git push origin feature/AmazingFeature`)
5. Open a Pull Request

License
-------

[](#license)

Distributed under the MIT License. See `LICENSE` for more information.

Contact
-------

[](#contact)

[![](https://camo.githubusercontent.com/c0ad3ece61855ee2ca223a53e4d7c33fbdb386ce98382e8ddd6379f6cbb4c0d7/68747470733a2f2f696d672e736869656c64732e696f2f7374617469632f76313f6c6162656c3d537769746368436174266d6573736167653d4167656e637926636f6c6f723d666637373031267374796c653d666f722d7468652d6261646765)](https://switchcat.agency)

Acknowledgements
----------------

[](#acknowledgements)

No major change has been brought to the original package. Basically ported it to php7.4 (fixed compatibility issues) and added a test suite. Some code optimization has been done in order to comply with code inspection standards. The package was marked "abandoned" and i found it very usefull. I simply decided to give it a second life.

Based on the work of:

- [hansott/range-regex](https://github.com/hansott/range-regex)
- [micromatch/to-regex-range](https://github.com/micromatch/to-regex-range)
- [jonschlinkert/to-regex-range](https://github.com/jonschlinkert/to-regex-range)

Credits
-------

[](#credits)

- [Hans Ott](https://github.com/hansott)
- [Felix Eloy](https://github.com/switchcat)

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity55

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 94.7% 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

Every ~2 days

Total

2

Last Release

2006d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/73464234?v=4)[SwitchCat Agency](/maintainers/switchcat)[@SwitchCat](https://github.com/SwitchCat)

---

Top Contributors

[![SwitchCat](https://avatars.githubusercontent.com/u/73464234?v=4)](https://github.com/SwitchCat "SwitchCat (18 commits)")[![codacy-badger](https://avatars.githubusercontent.com/u/23704769?v=4)](https://github.com/codacy-badger "codacy-badger (1 commits)")

---

Tags

phpphp74regexregex-patternregexpregular-expressionregular-expressionsswitchcat-frameworkvalidationregexglobMatchnumbernumericrangehansottexpansionbracerangesswitchcat

### Embed Badge

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

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

###  Alternatives

[composer/semver

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

3.3k489.6M672](/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.0k148.7M416](/packages/giggsey-libphonenumber-for-php)[respect/validation

The most awesome validation engine ever created for PHP

5.9k37.4M383](/packages/respect-validation)[propaganistas/laravel-phone

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

3.0k35.7M107](/packages/propaganistas-laravel-phone)[opis/json-schema

Json Schema Validator for PHP

64236.9M186](/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

8412.9M47](/packages/giggsey-libphonenumber-for-php-lite)

PHPackages © 2026

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