re = /_(1[6-9]|2[0-4])$/m
str = 'x2016_17_7
x2017_188
x2018_199
x2019_20_10
x2020_21_11
x2021_22_12
x2022_23_13
x2023_20_10
x202025_15
x2016_17_16
x2017_18_17
x2018_19_18
x2019_20_19
x2020_21_20
x2021_22_21
x2022_23_22
x2023_20_23
x2020_25_20'
# 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