0

I am learning RegEx for Powershell.

I have dummy email address as follow:

$emails = "
[email protected]
[email protected]
[email protected]
[email protected]
"

Below is my way to extract Email ID only (example: ks.ong88) with the help of Capture Group (.+)

$emails | Select-String -Pattern '(.+)@.+' -AllMatches |
    ForEach-Object { $_.Matches.Groups }

Below is part of the result return from commands above.

Groups    : {0, 1}
Success   : True
Name      : 0
Captures  : {0}
Index     : 2
Length    : 19
Value     : [email protected]
ValueSpan : 

Success   : True
Name      : 1
Captures  : {1}
Index     : 2
Length    : 8
Value     : ks.ong88
ValueSpan : 

Groups    : {0, 1}
Success   : True
Name      : 0
Captures  : {0}
Index     : 22
Length    : 17
Value     : [email protected]
ValueSpan : 

Success   : True
Name      : 1
Captures  : {1}
Index     : 22
Length    : 8
Value     : jyan8888
ValueSpan : 

I have tried for an hour and still struggling to get the Value within Captures:[1] Appreciate your advice.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.