2011-08-11 68 views

回答

11

尝试这种情况:

var s = " a b c"; 
print(s.replace(/^\s+/, function(m){ return m.replace(/\s/g, '.');})); 

它打印:

...a b c 

测试在Ideone:http://ideone.com/v1faQ

0

什么:

/^([ ]+)/ 

我不知道\s的伎俩,而一个普通的应该能够处理这个!

+0

这只提供 '.testing 1 2 3'。 一期。 – Miriam

+0

哎呀,对不起,我需要用这个预见,有一刻=) – elslooo

+0

[Deson't work](http://jsfiddle.net/FT4rP/1/) – qwertymk

1

替代(忽略strnigs瓦特/没有非空间)

var newStr = ""; 
newStr = (newStr = Array(str.search(/[^\s]/) + 1).join(".")) + str.substr(newStr.length);