PowerShell - Regular ExpressionsYou want to extract all email addresses from a text string in PowerShell. Which regex pattern is best suited for this task?A\\d+@\\w+\\.comB[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2}C[a-z]+@[a-z]+\\.netD@.+Check Answer
Step-by-Step SolutionSolution:Step 1: Understand email regex componentsEmails have username with letters, digits, special chars, then @, domain, dot, and TLD.Step 2: Evaluate each patternA matches common email format with username and domain parts; B and C are too restrictive; D matches any @ followed by anything.Final Answer:Pattern A correctly matches general email addresses -> Option BQuick 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 partsNot escaping dot in domainMatching incomplete emails
Master "Regular Expressions" in PowerShell9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepVisualTryChallengeProjectRecallTime
More PowerShell Quizzes Error Handling - Throw statement - Quiz 8hard Error Handling - Why error handling prevents script failure - Quiz 13medium File and Directory Operations - Why file management is core to scripting - Quiz 5medium File and Directory Operations - Why file management is core to scripting - Quiz 10hard File and Directory Operations - Test-Path for existence checks - Quiz 7medium File and Directory Operations - Writing files (Set-Content, Out-File) - Quiz 12easy Functions - Pipeline input (ValueFromPipeline) - Quiz 11easy Regular Expressions - Named captures - Quiz 5medium Regular Expressions - Regex with Select-String - Quiz 7medium Working with Objects - Measure-Object for statistics - Quiz 9hard