In C #, regular expressions can be used to filter HTML characters. For example, when verifying user input, HTML characters must be filtered to ensure security.
Using system. Text. regularexpressions;
RegEx. Replace (htmlcode, "<[^>] +> ","");
Explanation: <indicates that it starts with "<"
[^>] [^...] Match any character, but do not match the character followed by ^, that is, if "<>" appears in the string, it will not be filtered because it is part of the HTML Tag.
The plus sign matches at least one search item.
The last is>, indicating that the HTML Tag ends with>.
In C #, regular expressions can be used to filter HTML characters. For example, when verifying user input, HTML characters must be filtered to ensure security.
Using system. Text. regularexpressions;
RegEx. Replace (htmlcode, "<[^>] +> ","");
Explanation: <indicates that it starts with "<"
[^>] [^...] Match any character, but do not match the character followed by ^, that is, if "<>" appears in the string, it will not be filtered because it is part of the HTML Tag.
The plus sign matches at least one search item.
The last is>, indicating that the HTML Tag ends with>.