re = /^(?=\S{8,20}$)(?=\D*\d)(?![0-9_]).{6,18}?(.)\1$/mi
str = '+234567899
a_1de*Gg
xy1Me*__
!41deF_hij2lMnopq3ss
C234567890123$^67800
*5555555
sDF564zer""
!!!!!!!!!4!!!!!!!!!!
abcdefghijklmnopq9ss
a_1+Eff
B41def_hIJ2lmnopq3stt
abCDefghijklmnopqrss5
A_4 e*gg
__1+Eff
841DEf_hij2lmnopq3stt
a_1+eFg
b41DEf_hij2lmnopq3st
abCDefghijklmnopqrss
abcdef+++dF
!!!!!!!!!!!!!!!!!!!!
'
# 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