【发布时间】:2012-02-04 18:05:39
【问题描述】:
如果用户提交如下字符串:
我的客厅计划#plans #livingroom @cbmeeks #design @moe @larry - 这太酷了!
我想要以下数组/字符串:
text = "My living room plans"
tags = ['plans', 'livingroom', 'design']
people = ['cbmeeks', 'moe', 'larry']
description = "this is cool!"
每个提交的字符串都以text 开头。没有@、- 等。我不必担心用户以标签或人开头。细分应该看起来像这样,除了 TEXT 总是在第一位之外,任何顺序都可以。
TEXT [-description] [#tags] [@people]
编辑 我似乎无法弄清楚如何正确抓住它们。例如:
a = "My living room plans #plans #livingroom @cbmeeks #design @moe @larry -this is cool!"
/#\w+/.match(a).to_a
#=> ["#plans"] -- only grabs first one
【问题讨论】:
-
你能告诉我们你到目前为止写了什么吗?
-
a.scan /..../是你要找的。span>
标签: ruby string text-parsing