0

C# Code:-

dynamic RetArgs = new JObject();
RetArgs.abcTest= System.Text.RegularExpressions.Regex.Replace(abcTest, @"<[^>]*(>|$)|&nbsp;|&zwnj;|&raquo;|&laquo;", string.Empty).Trim();

showing parameter value:-

<div style="box-sizing: border-box; margin: 0px; padding: 0px; border: 0px; font-variant-numeric: inherit; font-variant-east-asian: inherit; font-stretch: inherit; line-height: inherit; font-family: Arimo; vertical-align: baseline; color: rgb(0, 0, 0);">
    Take your medicines as per following directions for 1 month/ 1 महिने के लिए</div>

expected result :-

Take your medicines as per following directions for 1 month/ 1 महिने के लिए
Martin Devillers
  • 17,293
  • 5
  • 46
  • 88
Dip Girase
  • 439
  • 1
  • 7
  • 18
  • 1
    I think the normal suggestion here is to use something designed for parsing HTML, such as HtmlAgilityPack. Can you advice why/how your current solution isn't working in this case? – ProgrammingLlama Feb 27 '19 at 07:28
  • @john actually this my post method this input parameter pass. and this value insert in ck-editor then generated this values – Dip Girase Feb 27 '19 at 08:38
  • @john current solution not working but i am just try it. – Dip Girase Feb 27 '19 at 08:39
  • Before you try to write regex to parse html, take a look at this [RegEx match open tags except XHTML self-contained tags](https://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/1732454#1732454) – TheGeneral Feb 27 '19 at 08:40
  • The current solution worked for me when I tested it against the "showing parameter value" example - I got the "expected result" out of `Regex.Replace`. "not working" isn't an accurate description of the problem because "not working" encompasses everything from throwing an exception to returning a blank string to returning your string still with HTML in it, etc. – ProgrammingLlama Feb 27 '19 at 08:41

1 Answers1

0

I recommend using HtmlAgilityPack (available on NuGet)

This code:

string html = "<div style="box-sizing: border-box; margin: 0px; padding: 0px; border: 0px; font-variant-numeric: inherit; font-variant-east-asian: inherit; font-stretch: inherit; line-height: inherit; font-family: Arimo; vertical-align: baseline; color: rgb(0, 0, 0);">
    Take your medicines as per following directions for 1 month/ 1 महिने के लिए</div>";
var htmlDoc = new HtmlAgilityPack.HtmlDocument();
htmlDoc.LoadHtml(description);
var fixedHtml = htmlDoc.DocumentNode.InnerText;

Produces this output:

Take your medicines as per following directions for 1 month/ 1 महिने के लिए
Martin Devillers
  • 17,293
  • 5
  • 46
  • 88