Remove all occurrences except last? December 20, 2023 by Tarik You can use regex with positive look ahead, "1.2.3.4".replace(/[.](?=.*[.])/g, "");