Bird
0
0

You want to extract date components from '2024-06-15' using named captures in PowerShell. Which regex pattern correctly captures year, month, and day?

hard📝 Application Q8 of 15
PowerShell - Regular Expressions
You want to extract date components from '2024-06-15' using named captures in PowerShell. Which regex pattern correctly captures year, month, and day?
A^(?<day>\d{2})-(?<month>\d{2})-(?<year>\d{4})$
B(?<year>\d{2})/(?<month>\d{2})/(?<day>\d{4})
C(?<year>\d{4})(?<month>\d{2})(?<day>\d{2})
D^(?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2})$
Step-by-Step Solution
Solution:
  1. Step 1: Analyze date format

    Input is 'YYYY-MM-DD', so year=4 digits, month=2 digits, day=2 digits separated by dashes.
  2. Step 2: Match pattern to input

    ^(?\d{4})-(?\d{2})-(?\d{2})$ matches exactly this format with named groups and anchors start/end.
  3. Final Answer:

    ^(?\d{4})-(?\d{2})-(?\d{2})$ -> Option D
  4. Quick Check:

    Match format exactly with named groups [OK]
Quick Trick: Match input format exactly with named groups [OK]
Common Mistakes:
  • Swapping day and year positions
  • Using wrong separators
  • Missing anchors causing partial matches

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes