re = /^(?!.*[@\.\_\d])[A-Za-z\x{00C0}-\x{00FF}][A-Za-z\x{00C0}-\x{00FF}\'\-]+([\ A-Za-z\x{00C0}-\x{00FF}][A-Za-z\x{00C0}-\x{00FF}\'\-]+)*/m
str = 'Pedro
Juan Andrés
Angel María España
Peter Thorne-Smidth
Flor@s
- it doesn\'t match if first comes a space!
- numbers @ _ . and oder special chars are not allowed'
# 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