簡體   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