Answer the question
In order to leave comments, you need to log in
How to write a regular expression that will split 3 digit characters?
Good day everyone!
Please tell me how to write a regular expression that will split the numbers into 3 rows, if I may say so, putting a space between the rest?
example:
1) `123456` => `123 456`
2) `12345` => `123 45`
3) `1234` => `123 4`
Answer the question
In order to leave comments, you need to log in
export const format_number = (str, delimiter = '\u202f') => {
// \u202f — неразрывный узкий пробел
return str.toString().replace(/(\d)(?=(\d\d\d)+([^\d]|$))/g, '$1' + delimiter);
};
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question