Backport PR #4609: Fix bytes regex for Python 3.