re = /(t(?:h[uứ])? ?(?:tư|[2-7]|hai|ba|năm|sáu|bảy)|chủ nhật)( *)(?: ?(?:đầu|cuối)? ?(?:tuần (?:trước|sau|này)))?$/m
str = 'thứ 2
thứ 3
thứ 4
thứ 5
thứ 6
thứ 7
t2
t3
t4
t5
t6
t7
thứ hai
thứ ba
thứ tư
thứ2
thứ3
chủnhật
Chủ nhật
thứ hai cuối tuần sau
thứ ba cuối tuần sau
thứ tư cuối tuần sau
thứ năm cuối tuần sau
thứ năm đầu tuần sau
thứ sáu đầu tuần sau
thứ bảy tuần sau
chủ nhật tuần trước
chủ nhật tuần này
t8 cuối tuần này
thuhai
thuba
thutu
thunam
tha thu
'
# 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