DBremen
8/21/2015 - 3:28 PM

RegEx.Replace Examples

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]
    }
})