Search code examples
phppreg-replacepreg-replace-callback

php preg_replace working only if there's ending space in string


I have this pattern:

preg_replace_callback('#@abc\((.*?)\)(.*?)@end.#is', ..

My template string:

$test = "@abc('test')<h1>test</h1>@end"; // not working
$test2 = "@abc('test')<h1>test</h1>@end "; // working

Why it doesn't work if there's no space after @end?


Solution

  • As @Rizier123 pointed out, this is the correct regex:

    preg_replace_callback('#@abc\((.*?)\)(.*?)@end#is', ..