PHP code example of hansott / range-regex

1. Go to this page and download the library: Download hansott/range-regex library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

hansott / range-regex example snippets

 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