Bird
0
0

Identify the error in this PowerShell regex usage:

medium📝 Debug Q6 of 15
PowerShell - Regular Expressions
Identify the error in this PowerShell regex usage:
$text = 'abc123'; if ($text -match '\d++') { 'Match' }
ANo error, code runs fine
BMissing escape for \d
CIncorrect use of -match operator
DInvalid quantifier ++ in regex
Step-by-Step Solution
Solution:
  1. Step 1: Analyze the regex pattern '\d++'

    ++ is not a valid quantifier in standard regex syntax.
  2. Step 2: Understand PowerShell regex rules

    PowerShell uses .NET regex which does not support ++ quantifier; this causes an error.
  3. Final Answer:

    The pattern has an invalid quantifier ++ causing an error -> Option D
  4. Quick Check:

    Invalid quantifier ++ = Error [OK]
Quick Trick: Use + for one or more, avoid ++ quantifier [OK]
Common Mistakes:
  • Using ++ quantifier which is invalid
  • Not escaping \d properly
  • Misusing -match operator syntax

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes