This:
the( cat( sat( on( the( mat)?)?)?)?)?
would answer your question. Remove "optional group" parens "(...)?" for parts that are not optional, add additional groups for things that must match together.
the // complete match
the cat // complete match
the cat sat // complete match
the cat sat on // complete match
the cat sat on the // complete match
the cat sat on the mat // complete match
the dog sat on the mat // two partial matches ("the")
You might want to add some pre-condition, like a start of line anchor, to prevent the expression from matching the second "the" in the last line:
^the( cat( sat( on( the( mat)?)?)?)?)?
EDIT: If you add a post-condition, like the end-of-line anchor, matching will be prevented entirely on the last example, that is, the last example won't match at all:
the( cat( sat( on( the( mat)?)?)?)?)?$
Credits for the tip go to VonC. Thanks!
The post-condition may of course be something else you expect to follow the match.
Alternatively, you remove the last question mark:
the( cat( sat( on( the( mat)?)?)?)?)
Be aware though: This would make a single "the" a non-match, so the first line will also not match.