3v4l.org

run code in 500+ PHP versions simultaneously
<?php $s = "/**\n". "* @changelog https://github.com/rectorphp/rector/blob/master/docs/rector_rules_overview.md\n". "*/\n"; $annotation = '@changelog'; var_dump(extractAnnotationFromClass($s, $annotation)); function extractAnnotationFromClass(string $docComment, string $annotation): ?string { // @see https://regex101.com/r/oYGaWU/1 $pattern = '#' . preg_quote($annotation, '#') . '\s+(?<content>.*?)$#m'; preg_match($pattern, $docComment, $matches); return $matches['content'] ?? null; }

preferences:
112.21 ms | 1444 KiB | 5 Q