Apply style using python to regex search

There is a similar question about how to search & replace styles here but I don’t find the answer helpuf in my case. I’d like to apply to a searched regex some attributes like FontColor & FontWeight.

Here is what I’ve done:

def apply_style_to_orphan_timecode(self):
    bold = PropertyValue('CharWeight', 0, FontWeight.BOLD, 0)
    rd = self.doc.createReplaceDescriptor()
    rd.SearchRegularExpression = True
    rd.SearchString = '^\s?(\[\d{2}:\d{2}:\d{2}\])\s?$'
    rd.setPropertyValue('CharWeight', FontWeight.BOLD)
    rd.ReplaceString = "$1"

and the result is this error:

<class ''>: Unknown property: CharWeight

The replace descriptor itself does not have properties such as CharWeight which is why the error occurs. Instead, it has two attributes arrays of PropertyValue objects, one for searching and one for replacing.


Thank you dear ! I understand now and it works!