Comparison of regular expression patterns for numbers, alphabet blocks

Im has some lines like these

aa11b2s abc1sff3 a1b1sdd2 

etc .... I need to change these lines to these

 aa 11 b 2 s abc 1 sff 3 a 1 b 1 sdd 2 

Just say: I need to add a space between the blocks (number / alphabet with)

+6
source share
3 answers
 var str = 'aa11b2s'; console.log(str.replace(/([\d.]+)/g, ' $1 ').replace(/^ +| +$/g, '')); 
+2
source
 var str = 'aa11b2s'.replace(/([az]+|\d+)(?!$)/gi, '$1 '); 
+3
source
 result = subject.replace(/[az](?=[0-9])|[0-9](?=[az])/ig, "$& "); 

This corresponds to a letter followed by a number, or a figure followed by a letter, without using a second character. Then it replaces the first character with the same character followed by a space.

+2
source

Source: https://habr.com/ru/post/916323/


All Articles