$re = '`[ \t]*(CATCH_)?(TEMPLATE_)?(TEST_CASE_METHOD|SCENARIO|TEST_CASE)[ \t]*\([ \t\n]*\"[^\"]*\"[ \t\n]*(,[ \t\n]*\"[^\"]*\")?(,[ \t\n]*[^,\)]*)*\)+[ \t\n]*\{+[ \t]*(//[^\n]*[Tt][Ii][Mm][Ee][Oo][Uu][Tt][ \t]*[0-9]+)*`m';
$str = 'TEST_CASE ("test")
{
Hello world;
}
TEST_CASE ("test with spaces {} []")
{
Hello world;
}
TEST_CASE ("test ) ", "case")
{
Hello world;
}
TEST_CASE ("test () ")
{
Hello world;
}
TEST_CASE("all is good")
{
REQUIRE(true);
}
TEMPLATE_TEST_CASE("aa", "[]", int, double, foo) {
}
CATCH_TEMPLATE_TEST_CASE("foo", "[tag]", T1, T2) {
}
CATCH_TEST_CASE("bbb") {
}';
preg_match_all($re, $str, $matches, PREG_SET_ORDER, 0);
// Print the entire match result
var_dump($matches);
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for PHP, please visit: http://php.net/manual/en/ref.pcre.php