I would like to parse the following DocBlock / comment with regex. Code below
$subject = <<<HTML
/**
Theme Name: Hello world
*/
HTML;
$pattern = '/^\/(?:*)+Theme Name:(\s)?([\w]+)/';
preg_match($pattern, $subject, $matches);
print_r($matches);
Running the code output the following error..
Warning: preg_match(): Compilation failed: nothing to repeat at offset 6 in C:\xampp\htdocs\blog\test.php on line 11
*
in the (?:*)
means 0 or more times.
Do you mean \*
?
https://www.regex101.com/r/vH7lB3/1
Note that I also added \s*
before Theme
to match the new line character and spaces