Bird
0
0

How would you write a PowerShell regex pattern to match a string that contains exactly 2 to 4 lowercase letters anywhere, but must start and end with a digit?

hard📝 Application Q9 of 15
PowerShell - Regular Expressions
How would you write a PowerShell regex pattern to match a string that contains exactly 2 to 4 lowercase letters anywhere, but must start and end with a digit?
A^\d[a-z]{2,4}\d$
B\d^[a-z]{2,4}\d$
C^\d[a-z]{2,4}$\d
D^\d[a-z]{2,4}\d+$
Step-by-Step Solution
Solution:
  1. Step 1: Understand the requirement

    String must start with digit (^\d), then 2-4 lowercase letters ([a-z]{2,4}), and end with digit (\d$).
  2. Step 2: Check each option

    ^\d[a-z]{2,4}\d$ correctly places anchors and quantifiers; others misplace anchors or quantifiers.
  3. Final Answer:

    ^\d[a-z]{2,4}\d$ -> Option A
  4. Quick Check:

    Anchors and quantifiers correctly combined [OK]
Quick Trick: Place anchors ^ and $ at string ends [OK]
Common Mistakes:
  • Misplacing anchors inside pattern
  • Using + instead of exact quantifier
  • Confusing order of characters

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes