【发布时间】:2019-07-20 20:31:28
【问题描述】:
C#代码:-
dynamic RetArgs = new JObject();
RetArgs.abcTest= System.Text.RegularExpressions.Regex.Replace(abcTest, @"<[^>]*(>|$)| |‌|»|«", string.Empty).Trim();
显示参数值:-
<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>
预期结果:-
Take your medicines as per following directions for 1 month/ 1 महिने के लिए
【问题讨论】:
-
我认为这里的正常建议是使用为解析 HTML 而设计的东西,例如 HtmlAgilityPack。您能否建议您当前的解决方案为何/如何在这种情况下不起作用?
-
@john 实际上这是我的 post 方法这个输入参数传递。并将此值插入 ck-editor 然后生成此值
-
@john 当前解决方案不起作用,但我只是尝试一下。
-
在你尝试编写正则表达式来解析 html 之前,先看看这个RegEx match open tags except XHTML self-contained tags
-
当我针对“显示参数值”示例对其进行测试时,当前的解决方案对我有用——我从
Regex.Replace中得到了“预期结果”。 “不工作”并不是对问题的准确描述,因为“不工作”涵盖了从抛出异常到返回空白字符串到返回仍然包含 HTML 的字符串等所有内容。
标签: javascript c# asp.net asp.net-mvc-4