Last active
May 28, 2018 19:40
-
-
Save turboBasic/42f6d9dfed59205c8dbdce93bcb41986 to your computer and use it in GitHub Desktop.
[Get-RegexMatchExamples] Using regex matches in powershell. Get-Matches() gets all regex matches. Answers question "How do I iterate through text file and print all matched regex groups for each line in file?" #powershell #regex
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Get-Content SomeFile.ps1 | | |
ForEach { Select-String '(?ix) ^ \s* function \s+ ( [^{( ]+ ) \s* ( \( [^()]+ \) )? \{' -input $_ -Allmatch } | | |
ForEach { $_.Matches.Groups[1].Value } | |
Get-Content SomeFile.ps1 | Select-String '(?i)^function\s+((\w|-)+)' | ForEach { $_.Matches.Groups[1].Value } | |
Get-Content SomeFile.ps1 | | |
ForEach-Object { $_ -match '(?ix) ^ \s* function \s+ ( [^{( ]+ ) \s* ( \( [^()]+ \) )? \{' } | | |
Where-Object { $_ } | | |
ForEach-Object { $Matches[1] } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment