Advanced
Complex Pattern Matching Engine
Constructing a highly specific regular expression to validate multi-part data strings with conditional formatting.
📝 Prompt Content
Construct a single Regular Expression that validates a custom product code string. The string must start with 3 uppercase letters, followed by a hyphen. The next segment must be a numeric digit between 1 and 5. If the digit is 1, the following segment must be exactly 4 lowercase letters. If the digit is greater than 1, the following segment must be 6 alphanumeric characters. The string must end with an optional checksum digit. Explain the back-references and lookaheads used.