Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to use regular expressions to filter HTML tags in C #

Shulou Source: shulou.com Published: 2022-05-31 13:15:42 10月16日 Update

This article introduces the knowledge of "how to use regular expressions to filter HTML tags in C#". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

The details are as follows:

Public static string FilterHtmlTag (string s) {/ / Mark regular expression return Regex.Replace (s, @ "] * >", delegate (Match match) {string v = match.ToString (); / / Picture

The regular expression Regex rx = new Regex (@ "^ $", RegexOptions.Compiled | RegexOptions.IgnoreCase); / / if (rx.IsMatch (v)) {return v; / / keep the picture

} else {return "; / / filter out}});}

Everything on my side is filtered, so I directly use regular, no longer do anonymous delegate reservation p and br

Content = Regex.Replace (content, @ "/\\ S*\ / g", ", RegexOptions.IgnoreCase); content = Regex.Replace (content, @"] * > ",", RegexOptions.IgnoreCase); content = content + "." ; "how to use regular expressions to filter HTML tags in C#" is introduced here, thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Tags: Regular expressions tags clips content pictures more knowledge practicality learning next dilemma reality situation articles tags cases ribbons websites industries Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno macOS OPPO Reno Shulou Tech Info vpn Apple