Apply /g to regex to properly convert flags