从网络抓取中提取信息,我得到了这个名字:
>> temp
"Rob Bolden"
>>temp.split " " #space bar
["Rob Bolden"]
>>temp.split /\s/
["Rob Bolden"]
>>temp.split /\s+/
["Rob Bolden"]
>>temp.split /\W/
["Rob", "Bolden"] #what I expected
什么不是空格字符 ( /\s/
) 而是非单词字符 ( /\W/
)?
编辑
$ruby -v
ruby 1.9.2p290 (2011-07-09 revision 32553) [x86_64-darwin11.2.0]