Regex: matching a pattern that may repeat x times

Hi, i’m curious. How can i modify this expresssion so that it matches not only “alphanum-alphanum” but also “alphanum-alphanum-alphanum-alphanum” or any other number of repetitions of the pattern?

Here’s the expression:


$test = preg_match("/^[a-z0-9]+-*[a-z0-9]+$/i", $str);


preg_match('/^([a-z0-9]+-[a-z0-9]+)*$/im', $subject, $match);
print '<pre>' . print_r($match,1) . '</pre>';

rather

‘/^([a-z0-9]+(?:-[a-z0-9]+)+)$/im’

or if you want to match it exactly four times:

‘/^([a-z0-9]+(?:-[a-z0-9]+){3})$/im’