I have a post here that's not specifically directed towards this, but it explains some of the concepts surrounding it. It includes an example that changes the description dynamically, which I've copied below.

That code looks nice but it only updates the unidentified description. To modify both, you could repeat all of that but use DESC instead of UNIDENTIFIED_DESC. Or you could use a loop which lets you perform the same changes on both descriptions. This is the macro we use in IR to do that.

It doesn't contain any of the REPLACE_TEXTUALLYs that determine what changes are made to the text. Those are defined in a separate macro. What you do is call this macro and provide it the name of another macro that has those, like this.

Both descriptions will then have all instances of 1d4 replaced with 1d7. Keep in mind that this might remove instances of 1d4 that you didn't really want to change.

The way we used to resolve this in IR was to instead look for a match of something like "Damage: 1d4" (but with regexp character classes to catch extra spaces and tabs and other stupid things that might otherwise prevent a match).

I don't have a good example of that in the current code because we now do all that in a giant macro that handles arbitrary changes to speed factor, THAC0, and damage. I've never looked too carefully at it because it's complicated, but it's in here listed as wc_update if you want to try to take advantage of it.