1. Go to this page and download the library: Download yoeunes/regex-parser 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/ */
yoeunes / regex-parser example snippets
use PHPRegex\Toolkit\Regex;
use PHPRegex\Redos\RedosMode;
$regex = Regex::create([
'runtime_pcre_validation' => true,
]);
// Parse a pattern into AST
$ast = $regex->parse('/^hello world$/i');
// Validate pattern syntax and semantics
$result = $regex->validate('/(?<=test)foo/');
if (!$result->isValid) {
echo $result->error;
}
// Check for ReDoS (theoretical by default)
$analysis = $regex->redos('/(a+)+$/');
echo $analysis->severity->value; // 'critical'
echo $analysis->headline(); // 'Exponential backtracking (proven)'
echo $analysis->witness->render(); // '"a" x n . "!"': the input that triggers it
// Optional: replay the attack on the running PCRE
$confirmed = $regex->redos('/(a+)+$/', mode: RedosMode::Confirmed);
echo $confirmed->isConfirmed() ? 'confirmed' : 'theoretical'; // 'confirmed'
// Get human-readable explanation
echo $regex->explain('/\d{4}-\d{2}-\d{2}/');
// Lay a long pattern out over lines under x, or compact it back to one
$laidOut = $regex->format('/^(?<user>[\w.+-]+)@(?<domain>(?:[a-z0-9-]+\.)+[a-z]{2,})$/i', 40)->pattern;
echo $regex->compact($laidOut)->pattern; // the one-line pattern again