Need Javascript code to remove sections from a string

Discussion in 'JavaScript' started by ruby, Jun 22, 2008.

  1. #1
    HI all... I have a string in javascript that looks something like this:

    a="/* COMMENT ! */A.at_1:hover, A.at_pow_by_5978:hover { color: #F9E67F; text-decoration: underline; }/* COMMENT2 */.at_image { border-width:0px;}";

    I need some code (regular expression) that will remove all the text between the /* and */ set of strings.

    So for example in this above string I want it to look like this afterwards:


    a="A.at_1:hover, A.at_pow_by_5978:hover { color: #F9E67F; text-decoration: underline; }.at_image { border-width:0px;}";


    Can someone write that for me please?
     
    ruby, Jun 22, 2008 IP
  2. ruby

    ruby Well-Known Member

    Messages:
    1,854
    Likes Received:
    40
    Best Answers:
    1
    Trophy Points:
    125
    #2
    All sorted... for anyone interested solution is:

    a.replace(/\/\*.*?\*\//g, "")
     
    ruby, Jun 22, 2008 IP
  3. code-rush

    code-rush Guest

    Messages:
    25
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks for the solution, ruby. I was looking for something similar myself!
     
    code-rush, Jun 23, 2008 IP