假设我有一个包含以下内容的字符串:
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 ]
实现这一目标的最佳方法是什么?