一度に 3 文字 (ただし、任意の数) で文字列をグループ化しようとしています。このコードの使用:
"this gets three at a time".scan(/\w\w\w/)
私は得る:
["thi","get","thr","tim"]
しかし、私が取得しようとしているのは次のとおりです。
["thi","sge","tst","hre","eat","ati","me"]
これらも試すことができます:
sentence = "this gets three at a time"
sentence[" "] = ""
sentence.scan(/\w\w\w/) // no change in regex
または:
sentence = "this gets three at a time"
sentence[" "] = ""
sentence.scan(/.{1,3}/)
または:
sentence = "this gets three at a time"
sentence[" "] = ""
sentence.scan(/[a-zA-Z]{1,3}/)