Bird
0
0

You want to check if a string contains either "cat" or "dog" using -match. Which pattern correctly matches either word?

hard📝 Application Q15 of 15
PowerShell - Regular Expressions
You want to check if a string contains either "cat" or "dog" using -match. Which pattern correctly matches either word?
A"cat|dog"
B"cat&dog"
C"cat,dog"
D"cat dog"
Step-by-Step Solution
Solution:
  1. Step 1: Understand regex OR operator

    In regular expressions, the pipe symbol | means OR, so "cat|dog" matches either "cat" or "dog".
  2. Step 2: Evaluate other options

    Options A, B, and C do not represent OR in regex and will not match either word correctly.
  3. Final Answer:

    "cat|dog" -> Option A
  4. Quick Check:

    Use | for OR in regex patterns [OK]
Quick Trick: Use pipe | for OR in regex patterns [OK]
Common Mistakes:
  • Using commas or spaces instead of |
  • Using & which means AND in some contexts
  • Not knowing regex syntax for OR

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes