1
str = "This\n is a sample text for test"
str.scan(/\S.{0,15}\S(?=\s|$)|\S+/)
# => ["This", "is a sample text", "for test"]
這裏,它在換行符(\n
)存在時會分裂。我其實想要的輸出爲,如何在正則表達式掃描中轉義換行
["This\n is a", "sample text for", "test"]
我該如何實現這一目標?
謝謝@Tim!這正是我正在尋找的東西。 – Sayuj