squeeze - Should I have words' database to make it right?

A

Arie Kusuma Atmaja

s = 'Heiiiiiiiiiiiiii mauu kemannnnaaaaaaaaa?'
puts s.squeeze # right, means 'where r
u going?' (Indonesian)

indoscripts = 'Tq, canggihhh meeeennnn.......'
puts indoscripts.squeeze # should be canggih,
not cangih (Indonesian)

milis = 'Scholarships often go abegging'
puts milis.squeeze # should be abegging,
not abeging (English)

french = %Q/Salut! Je m'appelle Arie. Ruby tous les jours :)/
puts french.squeeze # should be Je
m'appelle, not m'apele

Should I have words' database to make it right?
 
R

Robert Klemme

Arie Kusuma Atmaja said:
s = 'Heiiiiiiiiiiiiii mauu kemannnnaaaaaaaaa?'
puts s.squeeze # right, means 'where r
u going?' (Indonesian)

indoscripts = 'Tq, canggihhh meeeennnn.......'
puts indoscripts.squeeze # should be canggih,
not cangih (Indonesian)

milis = 'Scholarships often go abegging'
puts milis.squeeze # should be abegging,
not abeging (English)

french = %Q/Salut! Je m'appelle Arie. Ruby tous les jours :)/
puts french.squeeze # should be Je
m'appelle, not m'apele

Should I have words' database to make it right?

As this is obviously a language depedent feature that's certainly the best
approach. You might get away with doing this:

# replace sequences of three or more subsequent characters
s.gsub(/(\w)\1{2,}/, '\\1')
=> "Hei mauu kemana?"
=> "Scholarships often go abegging"

You might as well anchor at word end if that helps:
=> "Hei mau kemannnna?"

Kind regards

robert
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,577
Members
45,054
Latest member
LucyCarper

Latest Threads

Top