My regex needs to match two words in a sentence, but only the second word needs to be replaced. The first word is actually a key to a dictionary where the substitute for the second word is fetched. In PERL it would look something like:
$sentence = "Tom's boat is blue";
my %mydict = {}; # some key-pair values for name => color
$sentence =~ s/(\S+)'s boat is (\w+)/$1's boat is actually $mydict{$1}/;
print $sentence;
How can this be done in python?