1. Go to this page and download the library: Download darshphpdev/easyregex 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/ */
// In your controller
// Use The Helper class RegexBuilder to build and validate regex
use RegexBuilder;
$regex = RegexBuilder::make()->startsWith()->literally('abc')
->anyLetterOf('A', 'B', 'C')
->zeroOrMore()
->where(function ($query) {
$query->digit()->smallLetter();
})->toRegexString();
// the above example will return the regex string /^abc[ABC]*([0-9][a-z])/
// you can also match your string against the generated regex
$regexObject = RegexBuilder::make()->startsWith()->literally('abc')
->anyLetterOf('A', 'B', 'C')
->zeroOrMore()
->where(function ($query) {
$query->digit()->smallLetter();
});
$isMatching = $regexObject->match('abcAAA5g'); // $isMatching = true
$isMatching = $regexObject->match('abdd5g'); // $isMatching = false
// you can also specify the wrapping symbol as an argument to the make() function
// default is '/'
$regex = RegexBuilder::make('#')->literally('a')
->letterPatternOf('ABC')
->zeroOrMore()
->toRegexString();
// the above example will return the regex string #a(ABC)*#
// you can also use the global helper regexBuilder()
$regex = regexBuilder()->make()->digit()
->capitalLetters('A', 'F')
->onceOrMore()
->toRegexString();
// the above example will return the regex string /[0-9][A-F]+/
// FOR FULL USAGE, SEE BELOW..