Are you asking how to do lookaheads with regular expressions? The regex lookahead pattern is (?=...) so to match type in type? the regex would be type(?=\?).
If you want to match all of type? but only capture type, then you could use (type)\?, and then use a capture syntax XML element like <capture number="1" name="mysyntax.type.optional" />. For an example, see Nova matching documentation.
If you don’t know about it yet, regex101.com is an incredibly useful tool for testing your regexes. It also has a reference in the lower right for finding the syntax for regex patterns.
Yes, scopes are defined by regular expression matches. So for a scope you want to reuse, you put it in a separate collection. Here’s an example collection from what you have above:
You then can use this collection in subscopes (for a scope with starts-with and ends-with elements) with an include element. So say you want to create a variable definition scope for a syntax that looks like this:
var name1: SomeType = some expression;
var name2: [SomeType];
The types collection can be reused/included in other scopes like function parameter types, return types, etc. Moreover, if this variable definition scope is in a collection, then that definition collection can be used in other subscopes to achieve the “recursive” behavior.