Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Removing tags from a long string
Message
De
18/01/2016 12:12:11
 
 
À
18/01/2016 09:56:47
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Versions des environnements
Environment:
VB 9.0
OS:
Windows 8.1
Network:
Windows 2008 Server
Database:
MS SQL Server
Application:
Web
Divers
Thread ID:
01629858
Message ID:
01629892
Vues:
32
>>Try this
>>
>>
>>internal static string RemoveHtmlTags(string s)
>>		{
>>			return Regex.Replace(s, @"<[^>]*>", "");
>>		}
>>
>
>Can you tell me the enhancements in that filter instead of this:
>
>
>		lcContent = System.Text.RegularExpressions.Regex.Replace(lcContent, "<.*?>", "")
>
The latter, ie
<.*?>
matches a left bracket, the minimum chars needed followed by a right bracket

the dot matches any char but a newline

The former, ie
<[^>]*>
matches a left bracket, any number of chars except the right bracket, followed by a right bracket
It matches newline char between the left and right brackets, while the first does not

eg (using square brackets instead of angle brackets)

The first pattern will fail here, the second will work
[tag]

attr="PPP"



[/tag]
Gregory
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform