re = /\b(AB)\D*(\d+)\S*?(\d\d)\b(?=[',]|-[A-Z]|$)(?!-[A-Z]+-[A-Z]+-[A-Z])/m
str = 'A=\'AB.224-QW-2018\'
B=\'AB.876-5-LS-2018\'
C=\'AB.26-LS-18\'
D=\'AB-123-6-LS-2017\'
IA-Mb-22L-AB.224-QW-2018-IA-Mb-22L\' F=\'ZX-ss-12L-AB-123-6-LS-2017-BC-22
A=\'AB.224-QW-2018\'
B=\'AB.876-5-LS-2018\'
C=\'AB.26-LS-18\'
D=\'AB-123-6-LS-2017\'
E=\'IA-Mb-22L-AB.224-QW-2018-IA-Mb-22L\'
F=\'ZX-ss-12L-AB-123-6-LS-2017-BC-22\'
G=\'AB.224-2018\'
H=\'AB.224/QW/2018\'
I=\'AB/224/2018\'
-AB-231-2-33-12-2017,AB-231-1-HD-2017,AB-231-2017
AB-231-2-33-RR-TTLT-ZA-2017'
# 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