如何在
等文本中扫描*|
和|*
之间的所有字符串
Today is *|date|*. Weather is *|weather_description|*.
使用Ruby "string...".scan(...)
。
我想获得一系列匹配项:["date", "weather_description"]
。
答案 0 :(得分:5)
"Today is *|date|*. Weather is *|weather_description|*.".scan(/\*\|(.*?)\|\*/).flatten
# => ["date", "weather_description"]