Currently tackling a Regex challenge.
let phones = ['321-1234567','+355 321 1234567','0103 1234500', '00 355 3211234567' ]
Desired results:
3211234567
+3553211234567
+3551031234500
+3553211234567
Implemented solution:
phones.forEach(phone => {
phone = phone.replace(/^0+/,'+355').replace(/[^+\d]+/g, '')
console.log(phone)
})
Output:
3211234567
+3553211234567
+3551031234500
+3553553211234567 --->incorrect , supposed to be: +3553211234567
The current implementation only works for the first three elements in the array, failing to handle the last case where two zeros need replacing with + when starting with 00.
To address this,
How can I achieve this using Regex, or should I resort to conditional statements like if phone.startsWith()
?
This question offers unique circumstances compared to other solutions available online.