Easy way to replace all non-alpha numeric chars in a string?

Discussion in 'Ruby' started by deja, May 31, 2006.

  1. deja

    deja Guest

    Is there an easy (clean) method to replace all non-alpha numeric chars
    in a string with and underscore?

    for example:

    I want to transform the following string:

    "The book titled 'Ruby is Great' was written on 05/31/2006"

    into:

    "The_book_titled__Ruby is Great__was written on 05_31_2006"

    Thank you in advance!
     
    deja, May 31, 2006
    #1
    1. Advertisements

  2. No. Commas are no meta characters in character classes:
    => ","

    You rather want
    => "_"

    Alternatively this may work as well
    => "_"

    Cheers

    robert
     
    Robert Klemme, May 31, 2006
    #2
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.