Created
August 21, 2015 15:28
-
-
Save DBremen/d137f3d96d69b53700a8 to your computer and use it in GitHub Desktop.
RegEx.Replace Examples
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
#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