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

Discussion in 'Ruby' started by Arie Kusuma Atmaja, Mar 21, 2005.

  1. 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?

    --

    Best Regards,
    Arie Kusuma Atmaja
     
    Arie Kusuma Atmaja, Mar 21, 2005
    #1
    1. Advertisements

  2. "Arie Kusuma Atmaja" <> schrieb im Newsbeitrag
    news:...
    > 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')

    >> s = 'Heiiiiiiiiiiiiii mauu kemannnnaaaaaaaaa?'

    => "Heiiiiiiiiiiiiii mauu kemannnnaaaaaaaaa?"
    >> s.gsub(/(\w)\1{2,}/, '\\1')

    => "Hei mauu kemana?"

    >> s = 'Scholarships often go abegging'

    => "Scholarships often go abegging"
    >> s.gsub(/(\w)\1{2,}/, '\\1')

    => "Scholarships often go abegging"

    You might as well anchor at word end if that helps:

    >> s = 'Heiiiiiiiiiiiiii mauu kemannnnaaaaaaaaa?'

    => "Heiiiiiiiiiiiiii mauu kemannnnaaaaaaaaa?"
    >> s.gsub(/(\w)\1+\b/, '\\1')

    => "Hei mau kemannnna?"

    Kind regards

    robert
     
    Robert Klemme, Mar 21, 2005
    #2
    1. Advertisements

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Peter Strøiman
    Replies:
    1
    Views:
    2,375
    Peter Strøiman
    Aug 23, 2005
  2. Richard Heathfield
    Replies:
    7
    Views:
    627
    Barry Schwarz
    Oct 5, 2003
  3. utab

    Words Words

    utab, Feb 16, 2006, in forum: C++
    Replies:
    6
    Views:
    681
    Daniel T.
    Feb 16, 2006
  4. BerlinBrown
    Replies:
    6
    Views:
    7,040
  5. Lasse Edsvik

    replace words with bold words

    Lasse Edsvik, Oct 5, 2003, in forum: ASP General
    Replies:
    9
    Views:
    485
  6. Joshua Muheim
    Replies:
    5
    Views:
    269
    Phlip
    Aug 11, 2007
  7. Oran
    Replies:
    2
    Views:
    839
  8. pantagruel
    Replies:
    8
    Views:
    770
    Dr John Stockton
    Jul 22, 2006
Loading...