Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regular expression pattern matching for number,alphabetcic blocks

Im having some strings like these

aa11b2s
abc1sff3
a1b1sdd2

etc.... i need to change these strings to these

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

Simply saying..i need to add a space between each(number/alphabetic s) blocks

like image 392
coolguy Avatar asked May 22 '12 04:05

coolguy


2 Answers

var str = 'aa11b2s'.replace(/([a-z]+|\d+)(?!$)/gi, '$1 ');
like image 197
Prince John Wesley Avatar answered Oct 06 '22 03:10

Prince John Wesley


var str = 'aa11b2s';
console.log(str.replace(/([\d.]+)/g, ' $1 ').replace(/^ +| +$/g, ''));
like image 32
xdazz Avatar answered Oct 06 '22 02:10

xdazz