假設我有以下內容的字符串:如何閱讀格式化文本?
TODO | Eat spaghetti. | High | food, happiness
TODO | Get 8 hours of sleep. | Low | health
CURRENT | Party animal. | Normal | socialization
CURRENT | Grok Ruby. | High | development, ruby
DONE | Have some tea. | Normal |
TODO | Destroy Facebook and Google. | High | save humanity, conspiracy
TODO | Hunt saber-toothed cats. | Low | wtf
DONE | Do the 5th Ruby challenge. | High | ruby course, FMI, development, ruby
TODO | Find missing socks. | Low |
CURRENT | Grow epic mustache. | High | sex appeal
什麼是閱讀這些內容,並將其存儲的最佳方式中的對象結構如下說:
class example
attr_accessor status
attr_accessor description
attr_accessor priority
attr_accessor tags
end
我與嘗試以下的正則表達式:
/[a-zA-Z0-9]*/.match(text above)
但我得到的是
#<MatchData "TODO">
我希望得到的是
[TODO, Eat spaghetti, High, food, happiness, TODO ... etc ]
什麼是實現這一目標的最佳方式是什麼?
只要分割線與'|'和剝離它。 – zishe