Created
June 29, 2020 16:41
-
-
Save ninmonkey/238976a78d2e81991270e782e3e4b1dd to your computer and use it in GitHub Desktop.
Power
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 h1 { | |
param([string]$Label) | |
"`n#### $label ####`n" | |
} | |
$regex = '^(.+?)([^\.]*)$' | |
$regex_named = '^(?<name>.+?)(?<ext>[^\.]*)$' | |
h1 "inputs:" | |
Get-ChildItem c: -File | |
| where { $_.Name -match $regex } | select Name | |
h1 "un-named capture groups" | |
$regex | |
Get-ChildItem c: -File | ForEach-Object { | |
if($_.Name -match $regex ) { | |
[pscustomobject]$matches | |
} | |
} | Format-Table | |
h1 "named with 0 removed" | |
$regex_named | |
Get-ChildItem 'c:' -File | ForEach-Object { | |
if($_.Name -match $regex_named ) { | |
$matches.Remove(0) | |
[pscustomobject]$matches | |
} | |
} | Format-Table |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment