繁体   English   中英

使用正则表达式删除子字符串

[英]Remove a substring using Regex

如果有人可以帮助我使用正则表达式,那将是很棒的。 这是我的代码:

Regex.Replace("<_img src=\"abc.png\" /><_img class=\"shwimg\" alt=\"\" width=\"20\" height=\"20\" src=\"/images/img/do.png\" />",
                    "<_img .*? src=\"/images/img/do.png\" />", string.Empty)

我需要删除字符串的出现:

<_img class="shwimg" alt="" width="20" height="20" src="/images/img/do.png" />

发生的顺序

class="shwimg" alt="" width="20" height="20"

可能有所不同,因此我给了.*? 在模式中。 但是,我给出的模式不起作用,并且我无法替换字符串。

这是您要查找的正则表达式吗:

<_img [^>]*src="/images/img/do.png" />

(转义的双引号相同,可以在Regex.Replace调用中使用):

"<_img [^>]*src=\"/images/img/do.png\" />"

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM