Using powershell I want to replace a specific numeric part of a string with another number.
It’s best to describe this problem with an example.
$s = ' First part: 65 Second Part'
###################################################################
# this generates " First part: sixty-six Second Part" #
###################################################################
$s -replace '^(\s*First part:\s+)[0-9]+(.*)$', '$1sixty-six$2'
###################################################################
# But I want to generate" First part: 66 Second Part" #
###################################################################
$s -replace '^(\s*First part:\s+)[0-9]+(.*)$', '$166$2'
It doesn’t work.
How do I specify “$1 followed by the number 66” as opposed to “$166”?
Use this syntax:
${1}66$2Output: