I am trying to use python code to replace the character value 'K' with 'M' in the following code snippet, but not having much luck.
code:
import re
original_text = 'context PQ-4662-33-K64C-C-DDxxx-Sxxxx'
regex = re.compile(r'context\s.*\d[0-9]\-\w\w\-(K).*')
result = re.match(regex, original_text)
replace_attempt = regex.sub(r'M\1', original_text)
print(result.group(0))
print(result.group(1))
print(replace_attempt)
output:
context PQ-4662-33-K64C-C-DDxxx-Sxxxx
K
MK
Process finished with exit code 0
The desired output I am seeking:
context PQ-4662-33-M64C-C-DDxxx-Sxxxx