I am trying to format a kind of a board game notation which consists of tabs and spaces. The original string is looking like this:
1. \td11-d9 \te7-e10 \n2. \ta8-c8 \tg7-g10xf10 \n3. \th11-h9 \tf7-i7
I used this replace method to clean up all of the tabs and new lines
string.replace(/\s\s+/g, ' ').replaceAll('. ', '.');
So, after that the string is looking like this:
1.d11-d9 e7-e10 2.a8-c8 g7-g10xf10 3.h11-h9 f7-i7
However, I want to add more space before the number with the dot. So, the string must look like this with 3 spaces before the number of the move (the number with the dot):
1.d11-d9 e7-e10 2.a8-c8 g7-g10xf10 3.h11-h9 f7-i7
Can I also make all of these operations with a one line code or just one JavaScript method?
string.replace(/[^\S\n]+(?:\n(\d+\.))?/g, (_,x) => x ? ` ${x}` : " ").replaceAll('. ', '.')