locked
Stripping class, id attributes of the html string posted through fck editor RRS feed

  • Question

  • User-362908900 posted

    Hi,

    I have an fck editor in which the user posts some coments in my website.i want to strip the class, id attributes of the comment so posted.

    I know this can be done through regular expression .Can anyboby help me with this.

    Right now i have a code something like this but it's not working Frown

    private string RemoveAttributes(string input)
    {
    string re1 = "(.*?";	
    string re2 = "(class)";
    string re3 = "(=)";	
    string re4 = "(\".*?\"))";
    string re5 = "(id)";
    Regex regClass = new Regex(re1 + re2 + re3 + re4, RegexOptions.IgnoreCase | RegexOptions.Singleline);
    Regex regID = new Regex(re1 + re5 + re3 + re4, RegexOptions.IgnoreCase | RegexOptions.Singleline);
    input = regClass.Replace(input, new MatchEvaluator(ReplaceClassID));
    input = regID.Replace(input, new MatchEvaluator(ReplaceClassID));
    
    }
    private string ReplaceClassID(Match m)
    { return ""; }


    Friday, December 17, 2010 11:17 PM

All replies

  • User-129899387 posted

    Hi,

    Today is your happy day ;-)

                string input = "some html input"
                string pattern = @"(class|id)=[""']?((?:.(?![""']?\s+(?:\S+)=|[>""']))+.)[""']?";
                string output = Regex.Replace(input, pattern, String.Empty, RegexOptions.IgnoreCase | RegexOptions.Singleline);
    


    I has stolen regular expression from the following link:

    http://stackoverflow.com/questions/317053/regular-expression-for-extracting-tag-attributes


    Happy codding! :-) 

    Thursday, January 6, 2011 7:55 AM