re = /^.*\b202[0-9]\.(?:1[0-2]|0[1-9])\.(?:3[01]|[12][0-9]|0[1-9]) Week (?:5[0-3]|[1-4][0-9]|0?[1-9]) Forecast\.xlsm$/m
str = '/Users/X/Desktop/Test_Directory/2020.08.03 Week 53 Forecast.xlsm
/Users/X/Desktop/Test_Directory/2020.01.06 Week 2 Forecast.xlsm
/Users/X/Desktop/Test_Directory/2020.06.18 Week 25 Forecast.xlsm
/Users/X/Desktop/Test_Directory/2020.06.22 Week 26 Forecast.xlsm'
# Print the match result
str.scan(re) do |match|
puts match.to_s
end
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Ruby, please visit: http://ruby-doc.org/core-2.2.0/Regexp.html