Base regex encoding on str encoding.