remove the ending non legal character