1. Go to this page and download the library: Download regex-guard/regex-guard 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/ */
$guard->isRegexValid('/\w{0,1}/');
// true, regex is valid
$guard->isRegexValid('/\w{1,0}/');
// false, compilation fails: quantifiers are out of order
$guard->isRegexValid('/(\w)(?2)/');
// false, compilation fails: reference to non-existent subpattern at offset 7
$guard->validateRegexOrFail('/(\w)(?2)/');
// throws: compilation fails: reference to non-existent subpattern at offset 7
try {
if($regexGuard->match($pattern, $subject)) {
// match
} else {
// no match
}
} catch(\RegexGuard\RegexException $e) {
// handle the invalid regexp
}