replacement expression

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jon Paal [MSMD]

    replacement expression

    need some help with a str.replace expression to strip all content between any occurrence of parentheses and also remove parentheses
    ....

    str.replace(/\([\w\s]*\)/gi, "");

    any suggestions ?



  • apatheticagnostic

    #2
    Re: replacement expression

    On May 8, 2:06 pm, "Jon Paal [MSMD]" <Jon nospam Paal @ everywhere dot
    comwrote:
    need some help with a str.replace expression to strip all content between any occurrence of parentheses and also remove parentheses
    ...
    >
    str.replace(/\([\w\s]*\)/gi, "");
    >
    any suggestions ?
    Looks like it should, although you won't be stripping digits. What's
    the issue?

    Comment

    • Jon Paal [MSMD]

      #3
      Re: replacement expression


      "apatheticagnos tic" <apatheticagnos tic@gmail.comwr ote in message
      news:3fc20dfe-e95f-4272-b5f1-4108644186b5@m3 6g2000hse.googl egroups.com...
      On May 8, 2:06 pm, "Jon Paal [MSMD]" <Jon nospam Paal @ everywhere dot
      comwrote:
      need some help with a str.replace expression to strip all content between any occurrence of parentheses and also remove
      parentheses
      ...
      >
      str.replace(/\([\w\s]*\)/gi, "");
      >
      any suggestions ?
      Looks like it should, although you won't be stripping digits. What's
      the issue?

      It's not working...

      sample string is :

      "Electronic media (DVDs, CDs), Paper (books, photos), Textiles (clothes, linens), Furniture"

      should return:

      "Electronic media, Paper, Textiles, Furniture"


      Comment

      • apatheticagnostic

        #4
        Re: replacement expression

        On May 8, 3:23 pm, "Jon Paal [MSMD]" <Jon nospam Paal @ everywhere dot
        comwrote:
        "apatheticagnos tic" <apatheticagnos ...@gmail.comwr ote in message
        >
        news:3fc20dfe-e95f-4272-b5f1-4108644186b5@m3 6g2000hse.googl egroups.com...
        On May 8, 2:06 pm, "Jon Paal [MSMD]" <Jon nospam Paal @ everywhere dot
        >
        comwrote:
        need some help with a str.replace expression to strip all content between any occurrence of parentheses and also remove
        parentheses
        ...
        >
        str.replace(/\([\w\s]*\)/gi, "");
        >
        any suggestions ?
        >
        Looks like it should, although you won't be stripping digits. What's
        the issue?
        >
        It's not working...
        >
        sample string is :
        >
        "Electronic media (DVDs, CDs), Paper (books, photos), Textiles (clothes, linens), Furniture"
        >
        should return:
        >
        "Electronic media, Paper, Textiles, Furniture"
        It's the commas in the parens.

        str.replace(/\([^\)]*\)/gi, '');

        Comment

        • Doc O'Leary

          #5
          Re: replacement expression

          In article <ZIWdnV4pe96T3L 7VnZ2dnUVZ_jydn Z2d@palinacquis ition>,
          "Jon Paal [MSMD]" <Jon nospam Paal @ everywhere dot comwrote:
          need some help with a str.replace expression to strip all content between any
          occurrence of parentheses and also remove parentheses
          ...
          >
          str.replace(/\([\w\s]*\)/gi, "");
          >
          any suggestions ?
          \([^)]*\)

          --
          My personal UDP list: 127.0.0.1, 4ax.com, buzzardnews.com , googlegroups.co m,
          heapnode.com, localhost, ntli.net, teranews.com, vif.com, x-privat.org

          Comment

          • Dr J R Stockton

            #6
            Re: replacement expression

            In comp.lang.javas cript message <3fc20dfe-e95f-4272-b5f1-4108644186b5@m3
            6g2000hse.googl egroups.com>, Thu, 8 May 2008 11:40:40, apatheticagnost ic
            <apatheticagnos tic@gmail.compo sted:
            >On May 8, 2:06 pm, "Jon Paal [MSMD]" <Jon nospam Paal @ everywhere dot
            >comwrote:
            >need some help with a str.replace expression to strip all content between any occurrence of parentheses and also remove parentheses
            >...
            >>
            >str.replace(/\([\w\s]*\)/gi, "");
            >>
            >any suggestions ?
            >
            >Looks like it should, although you won't be stripping digits. What's
            >the issue?
            Posting correct untested answers requires real intelligence; one rarely
            finds that in the witterings of anonymous gmail users.


            The test string subsequently provided contains parenthesised commas; the
            RegExp does not accommodate that.

            This works on the test data : str.replace(/\([^)]*\)/g, "");
            - Electronic media , Paper , Textiles , Furniture

            And str.replace(/\s*\([^)]*\)/g, "");
            - Electronic media, Paper, Textiles, Furniture

            --
            (c) John Stockton, nr London UK. ???@merlyn.demo n.co.uk Turnpike v6.05 MIME.
            Web <URL:http://www.merlyn.demo n.co.uk/- FAQish topics, acronyms, & links.
            Check boilerplate spelling -- error is a public sign of incompetence.
            Never fully trust an article from a poster who gives no full real name.

            Comment

            Working...