Php正则表达式在斜杠之间获得4个字符串的结果

I'm having troubles with regex. I'm trying to isolate query results that are like :

string1/string2/string3/string4

string1/string2/string3/string4/string5

I want to find the first case from the two above, the one with the chain ending after "string4". I've tryied this regex that doesn't actually works :

$my_regex = "/^(.+)\/(.+)\/(.+)\/(.+)$/";
if (preg_match($my_regex, $category->name)) {
     ...
}

Am I missing something ?

With a regex, a solution could be :

$my_regex = "/^([^\/]+\/){3}[^\/]+$/";
if (preg_match($my_regex, $category->name)) {
     ...
}

Don't use a regex, use explode() function

$pieces = explode("/", $your_string); //pieces will be an array
foreach($pieces as $piece) {
   [...]
}