TypePHP 编译器
https://swoole.com/aot/
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
24 lines
686 B
24 lines
686 B
--TEST--
|
|
Symfony Finder Gitignore pattern: preg_replace_callback with static arrow function
|
|
--FILE--
|
|
<?php
|
|
function normalizeGitignoreCharacterClass(string $regex): string
|
|
{
|
|
return preg_replace_callback(
|
|
'~\\\\\[((?:\\\\!)?)([^\[\]]*)\\\\\]~',
|
|
static fn (array $matches): string => '['.('' !== $matches[1] ? '^' : '').str_replace('\\-', '-', $matches[2]).']',
|
|
$regex
|
|
);
|
|
}
|
|
|
|
function main(): void
|
|
{
|
|
var_dump(normalizeGitignoreCharacterClass('\\[a\\-z\\]'));
|
|
var_dump(normalizeGitignoreCharacterClass('\\[\\!0\\-9\\]'));
|
|
var_dump(normalizeGitignoreCharacterClass('plain'));
|
|
}
|
|
?>
|
|
--EXPECT--
|
|
string(5) "[a-z]"
|
|
string(6) "[^0-9]"
|
|
string(5) "plain"
|
|
|