This should work as well:

```python
new_text = re.sub(BOLDCODE_RE, r"<b>\2</b>", text)
```

The `\2` works as a backreference, the same as `match.group(2)`.

https://docs.python.org/2.6/library/re.html#re.sub