Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Removing tags from a long string
Message
From
18/01/2016 12:12:11
 
 
To
18/01/2016 09:56:47
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Environment versions
Environment:
VB 9.0
OS:
Windows 8.1
Network:
Windows 2008 Server
Database:
MS SQL Server
Application:
Web
Miscellaneous
Thread ID:
01629858
Message ID:
01629892
Views:
33
>>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
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform