0

I have this regex expression which I have sourced from a 3rd party. When I use it, I get a "not a enough )'s" error. Regex is not my strong point, although I cannot see anything obviously wrong.

code:

StringCollection sc = new StringCollection(); 
// Issue with following line
sc.Add(@"<(meta|link|/?o:|/?style|/?div|/?std|/?head|/?html|body|/?body|/?span|![)[^>]*?>");
foreach (string s in sc)  
{
   html = Regex.Replace(html, s, "", RegexOptions.IgnoreCase);  
}
return html; 

Error:

parsing "<(meta|link|/?o:|/?style|/?div|/?std|/?head|/?html|body|/?body|/?span|![)[^>]*?>" - Not enough )'s.

Thoughts?

SamJolly
  • 6,347
  • 13
  • 59
  • 125

1 Answers1

6

<(meta|link|/?o:|/?style|/?div|/?std|/?head|/?html|body|/?body|/?span|![)[^>]*?>

You're starting a second character with a ( and the other ) is in a character class. Try:

<(meta|link|/?o:|/?style|/?div|/?std|/?head|/?html|body|/?body|/?span|!\[)[^>]*?>

I've escaped the first [

Thom Puiman
  • 370
  • 2
  • 11