How to alter/sanitise widget values before they're saved?

We have a need to alter the configuration values of a widget after the user has entered them & before they're saved.

One use-case might be entering some code into a Dynamic Configuration field set to dataType=HTML.

Say we want to programatically check the HTML for a fully qualified URL, like..

<img src="">staging.blah.com/something.png">

And we want to strip off the leading domain, to leave it looking like

<img src="/something.png">

How would we go about doing a simple text replacement like that? Maybe using <propertyRule/>?

This is purely an example.. I'm after the approach we'd need to take so we could use it for things other than a URL and the Html control.

Thanks (and happy Thanksgiving to our American friends!)