Elegant way to replace substring in a regex with optional groups in Python? Given a string taken from the following set:

strings = [
    "The sky is blue and I like it",
    "The tree is green and I love it",
    "A lemon is yellow"
]


I would like to constuct a function which replaces subject, color and optional verb from this string with others values. 

All strings match a certain regex pattern as follow:

regex = r"(?:The|A) (?P&lt;subject&gt;\w+) is (?P&lt;color&gt;\w+)(?: and I (?P&lt;verb&gt;\w+) it)?"


The expected output of such function would look like this:

repl("The sea is blue", "moon", "white", "hate")
# =&gt; "The moon is white"


Here is the solution I come with (I can't use .replace() because there is edge cases if the string contains the subject twice for example):

def repl(sentence, subject, color, verb):
    m = re.match(regex, sentence)
    s = sentence
    new_string = s[:m.start("subject")] + subject + s[m.end("subject"):m.start("color")] + color
    if m.group("verb") is None:
        new_string += s[m.end("color"):]
    else:
        new_string += s[m.end("color"):m.start("verb")] + verb + s[m.end("verb"):]
    return new_string


Do you think there is a more straightforward way to implement this?
import re

regex = re.compile(
    r'(The|A) '
    r'\w+'
    r'( is )'
    r'\w+'
    r'(?:'
        r'( and I )'
        r'\w+'
        r'( it)'
    r')?'
)


def repl(sentence, subject, colour, verb=None):
    m = regex.match(sentence)
    new = m.expand(rf'\1 {subject}\2{colour}')
    if m[3]:
        new += m.expand(rf'\3{verb}\4')
    return new


def test():
    assert repl('The sky is blue and I like it', 'bathroom', 'smelly', 'distrust') == \
        'The bathroom is smelly and I distrust it'
    assert repl('The tree is green and I love it', 'pinata', 'angry', 'fear') == \
        'The pinata is angry and I fear it'
    assert repl('A lemon is yellow', 'population', 'dumbfounded') == \
        'A population is dumbfounded'


Essentially, invert the sections of the regex around which you put groups; they're the things you want to save.