Skip to content

Instantly share code, notes, and snippets.

@DBremen
Created August 21, 2015 15:28
Show Gist options
  • Save DBremen/d137f3d96d69b53700a8 to your computer and use it in GitHub Desktop.
Save DBremen/d137f3d96d69b53700a8 to your computer and use it in GitHub Desktop.
RegEx.Replace Examples
#Increase a number within a string by one
$data = 'XX3.txt', 'XX33.txt', 'XX333.txt'
$data | foreach{
[RegEx]::Replace($_, '(\d{1,3})', {1+$args[0].Value})
}
#Capitalize the second word within a sentence string
$script:counter = 0
[regex]::Replace('this is a test','\w+', {
$script:counter++
if ($counter -eq 2){
$args[0].Value.ToUpper()
}
else{
$args[0]
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment