extract text from a string

Discussion in 'Python' started by boris.smirnov, Nov 9, 2006.

  1. Hallo all,

    I have tried for a couple of hours to solve my problem with re but I
    have no success.

    I have a string containing: "+abc_cde.fgh_jkl\n" and what I need to
    become is "abc_cde.fgh_jkl". Could anybody be so kind and write me a
    code of how to extract this text from that string?

    thank you very much in advance
    regards,
    boris
     
    boris.smirnov, Nov 9, 2006
    #1
    1. Advertisements

  2. boris.smirnov

    Jon Clements Guest

    Perhaps if you described what the actual *criteria* is for the
    translation; for instance, "I need to keep only letters, numbers and
    punctuation characters" etc... Going by your example, it's tempting to
    suggest the best method would be string_name[1:-1] and that you don't
    need a regex.

    Jon.
     
    Jon Clements, Nov 9, 2006
    #2
    1. Advertisements

  3. ....or string_name.lstrip('+').rstrip('\n')

    I bet he doesn't need a regexp!
    Cheers,
     
    Roberto Bonvallet, Nov 9, 2006
    #3
  4. 'abc_cde.fgh_jkl'
     
    Grant Edwards, Nov 9, 2006
    #4
  5. Thank you very much.
    I needed this kick. :)
    Rg,
    Boris


    Grant Edwards napĂ­sal(a):
     
    boris.smirnov, Nov 9, 2006
    #5
    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.