If you need to replace text with some other text and keep a reference to the original text, you can use the backreferenceback reference placeholder $0:
'The problem was described in KB123456. Look it up.' – replace 'KB\d{6}', 'KB99999 (was: $0)'
If you need to replace text with some other text and keep a reference to the original text, you can use the backreferenceback reference placeholder $0: