0

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?

rringler
  • 61
  • 7

1 Answers1

2

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"
Michael Kohl
  • 66,324
  • 14
  • 138
  • 158
  • Both of these return an array of the days that I can work with. I guess it's time to take another look at String#scan. Thank you! – rringler May 04 '12 at 18:42