使用Ruby regex查找两个字符串之间的所有匹配项

时间:2015-04-23 14:42:53

标签: ruby regex

如何在

等文本中扫描*||*之间的所有字符串
Today is *|date|*. Weather is *|weather_description|*.

使用Ruby "string...".scan(...)

我想获得一系列匹配项:["date", "weather_description"]

1 个答案:

答案 0 :(得分:5)

"Today is *|date|*. Weather is *|weather_description|*.".scan(/\*\|(.*?)\|\*/).flatten
# => ["date", "weather_description"]