I need to format phone number for example by replace(): From: +48 XX XXX XX XX where X is a number. Example: +48 12 345 67 89 To: +48 XXX XXX XXX Example: +48 123 456 789 Edit: My work: First, I tried to remove the spaces in string: phone.replace(‘ ‘, ”);: Before: +48 12 312 31 23 After: +4812