我需要一些幫助理解以下用於將句子拆分爲單詞的Ruby代碼。使用正則表達式將字符串拆分爲單詞
class String
def words
scan(/\w[\w\'\-]*/)
end
end
這裏是行動的方法:
"This is a test of words' capabilities".words
回報
["This", "is", "a", "test", "of", "words'", "capabilities"]
什麼正則表達式(/ \ W [\ W \' - ] * /)意味着什麼?
你爲什麼不告訴我們你認爲這首先意味着什麼,以表明你試圖找出它? – 2013-02-15 21:59:22