Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/oracle/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html 匹配img标记的Regex模式_Html_Asp.net Mvc_Regex_Model View Controller_Asp.net Mvc 4 - Fatal编程技术网

Html 匹配img标记的Regex模式

Html 匹配img标记的Regex模式,html,asp.net-mvc,regex,model-view-controller,asp.net-mvc-4,Html,Asp.net Mvc,Regex,Model View Controller,Asp.net Mvc 4,使用MVC,看看这个示例,其中有以下HTML代码: <p>Duma</p><img url='..' /><p>Duma</p> 删除图像(显示[image])标记,仅显示文本(作为innerText) 我决定创建一个扩展,直到现在,只显示 Duma Duma public static class StringExtensions { public static string StripHtml (this string

使用MVC,看看这个示例,其中有以下HTML代码:

<p>Duma</p><img url='..' /><p>Duma</p>
删除图像(显示[image])标记,仅显示文本(作为innerText)

我决定创建一个扩展,直到现在,只显示

Duma Duma

public static class StringExtensions
{
    public static string StripHtml (this string inputString)
    {
       return Regex.Replace 
         (inputString, "<.*?>", string.Empty);
    }
}
杜马杜马
公共静态类扩展
{
公共静态字符串StripHtml(此字符串输入字符串)
{
返回正则表达式。替换
(inputString,“,string.Empty);
}
}
每次正则表达式与
img标记匹配时,如何添加[IMAGE]您可以尝试以下方法:

public static class StringExtensions
{
    public static string StripHtml (this string inputString)
    {
       return Regex.Replace(
       Regex.Replace(inputString, "<img.*?>", "[IMAGE]"), "<.*?>", string.Empty);
    }
}
公共静态类StringExtensions
{
公共静态字符串StripHtml(此字符串输入字符串)
{
返回正则表达式。替换(
Regex.Replace(inputString,“[IMAGE]”,“”,string.Empty);
}
}
它实际上调用了两个rege.Replace(),一个在另一个内部!st one将
标记替换为[IMAGE],然后替换字符串的其余部分,只保留
标记内的内容。

可能重复的
public static class StringExtensions
{
    public static string StripHtml (this string inputString)
    {
       return Regex.Replace(
       Regex.Replace(inputString, "<img.*?>", "[IMAGE]"), "<.*?>", string.Empty);
    }
}