Epressione regolare per poter eliminare tag da bufffer html

mercoledì 10 giugno 2009 - 16.57

yag Profilo | Junior Member

salve sto cercando di "realizzare" una regexp
per poter eliminare dei tag html da un buffer di testo html
(che rappresenta una pagina html base che si puà trovare in qualsiasi sito)

sto facendo una cosa del genere

public static string strip_tagsv2(string stringa,string tagdatogliere) { stringa = stringa.Trim(); stringa = stringa.Replace("&nbsp;", ""); string result = ""; String[] tags = tagdatogliere.Split('#'); foreach (string val in tags) { if (stringa.Length > 0) { Regex exp = new Regex("<"+val+"^>]+>", RegexOptions.IgnoreCase); result = exp.Replace(stringa, ""); result = result.Replace("\r", ""); result = result.Replace("\n", ""); result = result.Trim(); } stringa = result; } return stringa; }
Solo che non sortisce nessun effetto al testo

samar Profilo | Senior Member

Io uso queste istruzioni se può servirti, Vb
Dim RegExpression, Temp Temp = "Stringa in questione" RegExpression = New Regex("<[^>]*>") Temp = RegExpression.Replace(Temp, "") RegExpression = Nothing

funziona benissimo

yag Profilo | Junior Member

si certo... :)
ma questa elimina tutti i tag html ? giusto ? io vorrei poter
selezioanre quali eliminare...

samar Profilo | Senior Member

>si certo... :)

basta riadattare la regex, prova con <[*/" + val + ">]*>

yag Profilo | Junior Member

funziona! tnks...

samar Profilo | Senior Member

Accetta la risp. così si chiude
Partecipa anche tu! Registrati!
Hai bisogno di aiuto ?
Perchè non ti registri subito?

Dopo esserti registrato potrai chiedere
aiuto sul nostro Forum oppure aiutare gli altri

Consulta le Stanze disponibili.

Registrati ora !
Copyright © dotNetHell.it 2002-2025
Running on Windows Server 2008 R2 Standard, SQL Server 2012 & ASP.NET 3.5