Bird
0
0

In PowerShell, what type of value does the -match operator return when evaluating a string against a regex pattern?

easy📝 Conceptual Q1 of 15
PowerShell - String Operations
In PowerShell, what type of value does the -match operator return when evaluating a string against a regex pattern?
AA Boolean indicating if the pattern was found
BThe matched substring as a string
CAn array of all matches found
DThe index position of the match in the string
Step-by-Step Solution
Solution:
  1. Step 1: Understand -match behavior

    The -match operator returns $true if the regex pattern matches anywhere in the string, otherwise $false.
  2. Step 2: Differentiate from other outputs

    While $matches stores the matched substring, the operator itself returns a Boolean value.
  3. Final Answer:

    A Boolean indicating if the pattern was found -> Option A
  4. Quick Check:

    Check if $text -match 'pattern' returns $true or $false [OK]
Quick Trick: Returns true/false if pattern matches [OK]
Common Mistakes:
  • Assuming it returns the matched string directly
  • Confusing -match with -replace
  • Expecting an array of matches from -match

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes