Bird
0
0

You want to use the -match operator to check if a string contains either "apple" or "banana". Which regex pattern should you use?

hard📝 Application Q8 of 15
PowerShell - Regular Expressions
You want to use the -match operator to check if a string contains either "apple" or "banana". Which regex pattern should you use?
A"apple|banana"
B"apple&banana"
C"apple,banana"
D"apple?banana"
Step-by-Step Solution
Solution:
  1. Step 1: Understand regex alternation

    The pipe symbol | is used in regex to mean OR between patterns.
  2. Step 2: Evaluate options

    "apple|banana" uses "apple|banana" which matches either "apple" or "banana".
  3. Final Answer:

    "apple|banana" -> Option A
  4. Quick Check:

    Use '|' for OR in regex patterns [OK]
Quick Trick: Use '|' to match one pattern or another [OK]
Common Mistakes:
  • Using '&' which is not a regex OR operator
  • Using commas which do not separate alternatives in regex
  • Using '?' which means optional, not OR

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes