Fix #3852

Added test case from the aforementioned issue.
No longer reversing regex as it was problematic for constraints.
Fixing expectation for two optional subdomains with one missing.
Adding test cases for nested subdomains.