tomazzlender
tomazzlender

Reputation: 1123

Find all matches between two strings with Ruby regex

How to scan for all string between *| and |* in text like

Today is *|date|*. Weather is *|weather_description|*.

using Ruby "string...".scan(...).

I would like to get array of matches: ["date", "weather_description"].

Upvotes: 2

Views: 560

Answers (1)

shivam
shivam

Reputation: 16506

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

Upvotes: 5

Related Questions