Regular Expression - Substitute method

Hi All,

In the following mentioned code of Regexes that I am invoked Substitute function with arguments (replacement(r’\1***) and string). However, I could not understand the logic behind replacement argument. Appreciate if you can help me to extract the functionality and flow through outcome process.

import re


st = 'Agent Arun informed to Agent Vikram come down to talk with Agent ' \
     'Subham'


pattern = re.compile(r'Agent (\w)\w*')
print(pattern.sub(r'\1**', st))

Regards
Riyaz.