Don’t do that: I saw that many times, some people want to extract some numbers in a string and they use the Replace method several times.
1 2 3 |
$log = 'backup-full-22042015-disk-D' $date = $log -replace 'backup-full-', '' $date = $date -replace '-disk-D', '' |
or
$log -replace 'backup-full-', '' -replace '-disk-D', ''
It will return ‘22042015’ in this case, but I don’t like this approach because it is “too much” work and in case the prefix/suffix is changed, it does not work.
Do that: I like that one to simply match digits.
[regex]::match($log,'(\d+)').value