On 2/12/07, J. mp <joaomiguel.pereira / gmail.com> wrote:
> >
> > Note that, per your exact instructions, this allows:
> >   u_s_e_r_n_a_m_e
> >   u____________________________e
> >   z._-_.z
>
>
> Oh damm!! the first should  be allowed but second and the third should
> not be allowed

The regexp could be extended to allow this, but it gets ever more
convoluted and unreadable - you'd be better off doing a separate check
for a !~ /[^A-Za-z]{2,}/ (that is, "a does not match two
non-alphanumeric chars in a row"

>> tests = %w( u_s_e_r_n_a_m_e
 u____________________________e
 z._-_.z
)
=> ["u_s_e_r_n_a_m_e", "u____________________________e", "z._-_.z"]
>> tests.each {|a| p [a,  a !~ /[^A-Za-z]{2,}/]}
["u_s_e_r_n_a_m_e", true]
["u____________________________e", false]
["z._-_.z", false]

Also, play around with http://weitz.de/regex-coach/

martin