Reputation: 61
I've googled for a good bit now and I can't figure out this regex on my own. I'd like to pick up all the days of the week that occur between the 'Validation day:' and 'all_exception_rules' text:
String to search:
--- !ruby/object:IceCube::Schedule start_time: 2012-04-28 13:38:49.334561000 -07:00 end_time: duration: all_recurrence_rules: - !ruby/object:IceCube::WeeklyRule validations: :interval: - !ruby/object:IceCube::Validations::WeeklyInterval::Validation interval: 1 week_start: :sunday :base_hour: - !ruby/object:IceCube::Validations::ScheduleLock::Validation type: :hour :base_min: - !ruby/object:IceCube::Validations::ScheduleLock::Validation type: :min :base_sec: - !ruby/object:IceCube::Validations::ScheduleLock::Validation type: :sec :day: - !ruby/object:IceCube::Validations::Day::Validation day: - monday - tuesday - wednesday - thursday - friday all_exception_rules: []
The closest I could get on rubular was: /Validation day: - (.*) all_exception/
. This picks up all days (plus whitespace, and dashes) in rubular, but is returning Nil
in my rails app.
Any idea why this would work on rubular, but not my app?
Is there an easy way to pick up an array of the days without the whitespace and dashes?
Upvotes: 0
Views: 779
Reputation: 66837
Does this help?
s.scan(/-\s(\w+)\s/)
#=> [["monday"], ["tuesday"], ["wednesday"], ["thursday"], ["friday"]]
Or:
s.scan(/-\s(\w+)\s/).map(&:first).join(" ")
#=> "monday tuesday wednesday thursday friday"
Upvotes: 2