Bird
0
0

You want to extract all email addresses from a text string in PowerShell. Which regex pattern is best suited for this task?

hard📝 Application Q8 of 15
PowerShell - Regular Expressions
You want to extract all email addresses from a text string in PowerShell. Which regex pattern is best suited for this task?
A\\d+@\\w+\\.com
B[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2}
C[a-z]+@[a-z]+\\.net
D@.+
Step-by-Step Solution
Solution:
  1. Step 1: Understand email regex components

    Emails have username with letters, digits, special chars, then @, domain, dot, and TLD.
  2. Step 2: Evaluate each pattern

    A matches common email format with username and domain parts; B and C are too restrictive; D matches any @ followed by anything.
  3. Final Answer:

    Pattern A correctly matches general email addresses -> Option B
  4. Quick Check:

    General email pattern = [a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2} [OK]
Quick Trick: Use character classes and + quantifier for email parts [OK]
Common Mistakes:
  • Using too simple patterns missing parts
  • Not escaping dot in domain
  • Matching incomplete emails

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes