<?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; }
You have javascript disabled. You will not be able to edit any code.