Site icon Hip-Hop Website Design and Development

URL rewrite – unlimited nesting issue

I’m trying to create a new URL structure.

function custom_rewrite() {
   add_rewrite_rule('^project/([^/]+)/([0-9]+)/?$', 'index.php?pagename=$matches[1]&custom_param=$matches[2]', 'top');
}
add_action('init', 'custom_rewrite');

This code works well and I get the page:

_http://localhost/project/space/12345/

BUT this code also works for page:

_http://localhost/project/space/12345/oops/i/have/multiple/nesting/folders/

How can I fix RegEx to exclude unlimited nesting?