advanced
Advanced Regular Expression Construction
Generate and explain a complex regular expression for validating specific date formats and leap years.
📝 Contenu du Prompt
Act as a Regular Expression Expert. Construct a single, highly optimized regular expression that validates a date string in the format 'DD-MMM-YYYY' (e.g., 15-Feb-2024). The regex must strictly enforce valid days per month, including leap years for the Gregorian calendar, and reject invalid dates like 31-Apr-2023 or 29-Feb-2023. After providing the regex, break down every component of the pattern and explain the logic used to handle the leap year calculations and variable month lengths.