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

tom*_*der 2 ruby regex

如何扫描之间的所有字符串*||*文本一样

Today is *|date|*. Weather is *|weather_description|*.
Run Code Online (Sandbox Code Playgroud)

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

我想获得一系列的比赛:["date", "weather_description"].

shi*_*vam 5

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