re = /\(20(\d{2}|x{2})((\.|-)([0-9]{2}|x{2}|KW(\d{2}|x{2})|Q(x|[1-4])|(([0-9]{2}|x{2})(\.|-)([0-9]{2}|x{2}))))?\)/
str = '20000002000
200 0
(2022.xx2000.xx)
(2022.xx) 2000.xx
(2020-20)
(20xx-12)
(20xx.xx-11)
(2002-KW00.00)
(2002-KW00)
(2022.KWxx)
(2021.KW09)
(2021.KW09)
(2021.02)
2022.Qx
2032.Q4
(2020.xx)
2022-Q1
2022 Test
Test 20xx
20202020
.Qx
KW23
KWxx
(20xx)
(.-Q4)
2000-
2000.
'
# 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