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. Advertising

  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. Advertising

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. Big Bill
    Replies:
    7
    Views:
    441
    Big Bill
    May 7, 2004
  2. Mathias Waack

    squeeze and package imports

    Mathias Waack, Sep 25, 2003, in forum: Python
    Replies:
    2
    Views:
    289
    Mathias Waack
    Sep 27, 2003
  3. arnuld

    K&R2 section 2.8 (exercise 2.4) "squeeze"

    arnuld, Mar 13, 2007, in forum: C Programming
    Replies:
    5
    Views:
    477
    Barry Schwarz
    Mar 14, 2007
  4. luser-ex-troll

    META: relax topicality to squeeze the spam?

    luser-ex-troll, Mar 14, 2009, in forum: C Programming
    Replies:
    6
    Views:
    888
    luser-ex-troll
    Mar 17, 2009
  5. Oran
    Replies:
    2
    Views:
    608
Loading...

Share This Page