作者LPH66 (ha(ruhi|yate)ism)
看板java
标题Re: [问题] 请问string.split的用法...
时间Tue Apr 17 19:18:40 2007
※ 引述《[email protected] ( )》之铭言:
: 我run了程式 结果的确不一样
: 也看了正则表示式
: 但还是有点有看没董耶..
: 可不可以再解释一下...[\t]和[\t]+有什麽不同..谢谢
+ 相同於{1,} 表示前面那样东西可以出现一次以上
其他类似的字还有
* 相同於{0,}
? 相同於{0,1}
回到你的问题
会不一样的原因是因为
你只用[ \t]去match的话 「每个」空白或Tab都会当成一个分隔
所以在连续的分隔之间切出的就是空字串
如果用[ \t]+去match的话 连续的空白或Tab由於这个式子把它一次抓住了
於是全部一整串空白或Tab就会当成一个分隔
所以就不会有连续的分隔 自然空字串就不见了
--
'Oh, Harry, dont't you
see?' Hermione breathed. 'If she could have done
one thing to make
absolutely sure that every single person in this school
will read your interview, it was
banning it!'
---'Harry Potter and the order of the phoenix', P513
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 210.70.172.164