replace spaces

Discussion in 'Perl Misc' started by mud_saisem, Aug 3, 2009.

  1. mud_saisem

    mud_saisem Guest

    Hi There,

    Could somebody please let me know what the regular expression should
    look like if I wanted the only replace the spaces of words between "
    ".

    Example:
    string: 1,2,3,4 "5 6 7 8" 9,10,11 "12 13" 14,15,16
    result: 1,2,3,4 5_6_7_8 9,10,11 12_13 14,15,16
     
    mud_saisem, Aug 3, 2009
    #1
    1. Advertisements

  2. mud_saisem

    sln Guest

    s/"(.*?)"/$1/g

    If you have something else in mind for $1
    do it somewhere else s//&subcall/ge

    -sln
     
    sln, Aug 4, 2009
    #2
    1. Advertisements

  3. mud_saisem

    mud_saisem Guest

    I like your work !, I will make very good use of the example that you
    have supplied. Thanks for all the effort.

    I was trying the following which seemed to be on the right track but
    not quite there.

    's/"[^*"]*"/_/g'

    which was resulting in 1,2,3,4 _ 9,10,11 _ 14,15,16

    I just could not figure out how to replace the /_/g with /$1/g but
    with the spaces replaced with underscores. If that makes any sense.
     
    mud_saisem, Aug 4, 2009
    #3
    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.