I wonder if it is possible to write a regular expression that replaces all occurrences of something (e.g. whitespace), but not in the whole string, but a part of a string that is identified by some matched characters.

In my particular example, I would like to replace all spaces with underscores between an opening and a closing parenthesis (possibly with multiple occurrences of (...) in the line).