Bird
0
0

What is the issue with this PowerShell regex command?

medium📝 Debug Q7 of 15
PowerShell - Regular Expressions
What is the issue with this PowerShell regex command?
'abc' -match '\d+'
ASyntax error due to missing closing quote
BNo issue; it returns False because no digits are present
CRegex pattern is invalid because '+' cannot be used after '\d'
DThe command throws an exception
Step-by-Step Solution
Solution:
  1. Step 1: Check syntax

    The command is syntactically correct with properly closed quotes.
  2. Step 2: Understand the regex

    '\d+' matches one or more digits.
  3. Step 3: Analyze the string

    'abc' contains no digits, so the match fails.
  4. Final Answer:

    No issue; it returns False because no digits are present -> Option B
  5. Quick Check:

    Regex is valid; absence of digits leads to False [OK]
Quick Trick: Valid regex returns False if no match found [OK]
Common Mistakes:
  • Assuming syntax error due to regex quantifier
  • Expecting an exception on no match
  • Confusing regex pattern validity with match result

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes