简体   繁体   English

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

[英]Remove a substring using Regex

It would be great if someone could help me with the regex. 如果有人可以帮助我使用正则表达式,那将是很棒的。 This is my code: 这是我的代码:

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)

I need to remove the occurrence of the string: 我需要删除字符串的出现:

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

The order of the occurence of 发生的顺序

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

may vary, hence I've given .*? 可能有所不同,因此我给了.*? in the pattern. 在模式中。 However, the pattern I've given doesnt work and I'm not able to replace the string. 但是,我给出的模式不起作用,并且我无法替换字符串。

Is this the regex you're looking for?: 这是您要查找的正则表达式吗:

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

(here's the same with escaped double-quotes, ready for use in your Regex.Replace call): (转义的双引号相同,可以在Regex.Replace调用中使用):

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

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

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