2

我很想通过使用 Apples NSRegularExpressions 匹配和删除它们来摆脱 rssfeed 中的一些小图像。

<img src="somepic" height="1" width="1"> should be matched for removal
<img src="somepic" height="50" width="100"> -> should also be matched
<img src="somepic" height="100" width="100"> -> this one should not be matched

我目前的方法还没有奏效

<img(\s*[height|width]\s*=\s*"([0-9]|[1-9][0-9])"\s*+|[^>]+?)*>

我的猜测是捕获组存在一些问题(可能根本不需要)。有没有人暗示它为什么不工作?

4

2 回答 2

2

试试这个正则表达式:

<img[^>]*(?:height|width)\s*=\s*"[1-9]?[0-9]"[^>]*>

它解决了 Mattias Buelens 在评论中提到的小问题。

红字

于 2012-09-17T15:52:05.703 回答
1

这是c#正则表达式

(?<=<img).*?(height="([0-9]|[1-9][0-9])".*?width="([0-9]|[1-9][0-9])"|width="([0-9]|[1-9][0-9])".*?height="([0-9]|[1-9][0-9])").*?(?=>)

希望这可以帮助..

于 2012-09-17T16:01:05.823 回答