add_rewrite_rule with optional parameters

Found the solution, just had to remember all the ? marks.

It works when the regex is like this:

'index.php?catalogs=$matches[1]&p1=$matches[2]&p2=$matches[3]&p3=$matches[4]'