I wrote this code:
let regex = Regex {
        let newline = #/\r|\n|\r\n/#
        let doubleNewline = Repeat(newline, count: 2)
        let dateFormatter = DateFormatter()
        
        "# Title"
        newline
        Capture { ZeroOrMore(.any) }
        
        doubleNewline
        
        "# Subtitle"
        newline
        Capture { ZeroOrMore(.any) }
        
        doubleNewline
        
        "# Created at"
        newline
        TryCapture { OneOrMore(.any) } transform: { createdDateString in
            dateFormatter.date(from: String(createdDateString))
        }
        
        doubleNewline
        
        "# Exported at"
        newline
        TryCapture { OneOrMore(.any) } transform: { exportedDateString in
            dateFormatter.date(from: String(exportedDateString))
        }
        
        doubleNewline
        
        "# Article count"
        newline
        Capture {
            .localizedInteger
        }
        
        doubleNewline
        
        "# Articles"
        newline
        ZeroOrMore {
            #/[\s\S]/#
        }
        newline
    }
and the error occurs:
The compiler is unable to type-check this expression in reasonable time; try breaking up the expression into distinct sub-expressions
How should I fix this error?
What I tried
- Annotated type of the regex in this way:
let regex: Regex<(Substring, Substring, Substring, Date, Date, Int)> = Regex { ... }
- Make explicit the type of transformclosure in the twoTryCapture
TryCapture { OneOrMore(.any) } transform: { (createdDateString: Substring) -> Date in
    dateFormatter.date(from: String(createdDateString))
}
Neither resolved the error.
 
    