in reply to Variable substitute and capturing

One time when this came up I devised my own solution which I posted here. I like it because it doesn't use eval EXPR, and lets you specify the regexp however you want including modifiers.