Created
August 18, 2016 18:09
-
-
Save jcdickinson/cee4582448300c0d404bbff1f5669029 to your computer and use it in GitHub Desktop.
Select Regex
This file contains 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
Function Select-Regex { | |
Param( | |
[Parameter(ValueFromPipeline=$True)] $Input, | |
[Parameter(Mandatory=$True, Position=0)] [String] $Pattern | |
) | |
Begin { | |
$Regex = New-Object Regex $Pattern, 'ExplicitCapture' | |
} | |
Process { | |
$Input | ForEach-Object { $Regex.Matches($_) } | Where-Object { $_.Success } | ForEach-Object { | |
$Result = @{} | |
ForEach ($Group in $Regex.GetGroupNames()) | |
{ | |
Add-Member -InputObject $Result -MemberType NoteProperty -Name $Group -Value ($_.Groups[$Group].Value) | |
} | |
$Result | |
} | |
} | |
} | |
Get-ChildItem *.js | Get-Content | Select-Regex 'require\("(?<Require>.*?)"\)' | Select-Object -ExpandProperty Require |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment