Also, if you just want to match a literal `.` or a literal `$`, it may be faster to not use regular expressions at all:
```python
for char in [".", "$"]:
    fieldname = fieldname.replace(char, '%{:02x}'.format(ord(char)))
```