3v4l.org

run code in 300+ PHP versions simultaneously
<?php #BLM final class ABNFParser { private const ABNF_REGEX = <<<'REGEX' (?(DEFINE) (?<ALPHA>[A-Za-z]) (?<DIGIT>[0-9]) (?<SP>[\x20]) (?<WSP>[(?&SP)\x09]) (?<CR>\x0D) (?<LF>\x0A) (?<Repeat>(?:(?:(?&DIGIT)+(?:(?&DIGIT)*[\x2A](?&DIGIT)*)))) ) REGEX; public function parse(string $input, string $rule): ?string { // Build the query pattern dynamically based on the provided rule $pattern = sprintf('#%s(?&%s)#Aux', self::ABNF_REGEX, $rule); if (preg_match($pattern, $input, $matches)) { return $matches[0]; } return null; } } # Example Usage $parser = new ABNFParser(); $input = '2*4'; $rule = 'Repeat'; $parsedResult = $parser->parse($input, $rule); var_dump($parsedResult); // Outputs: string(3) "2*4"
Output for 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.28, 8.4.1 - 8.4.14, 8.5.0
string(3) "2*4"
Output for 8.4.15
/bin/php-8.4.15: /usr/lib/libm.so.6: version `GLIBC_2.38' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libm.so.6: version `GLIBC_2.35' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libc.so.6: version `GLIBC_2.34' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libc.so.6: version `GLIBC_2.38' not found (required by /bin/php-8.4.15)
Process exited with code 1.

preferences:
90.73 ms | 407 KiB | 5 Q