Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ninmonkey/238976a78d2e81991270e782e3e4b1dd to your computer and use it in GitHub Desktop.
Save ninmonkey/238976a78d2e81991270e782e3e4b1dd to your computer and use it in GitHub Desktop.
Power
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