1

我在objective-c中有这个正则表达式

NSString* searchString = [searchBlock stringByReplacingOccurrencesOfString:@"<(.*?)>" withString:@"" options: NSRegularExpressionSearch range:NSMakeRange (0, [searchBlock length])];

代码应该删除尖括号 <> 之间的所有内容,它似乎大部分时间都可以工作,但在这种情况下似乎失败了,我不知道为什么:

<a href="http://www.twitter.com/starkpo">
        <img height="120" width="124" alt="Follow us @starkpo." style="border: 0;"
        src="http://www.thestarkingtonpost.com/wp-content/uploads/2009/09/twitter-master.jpg" 
        title="Join us on Twitter" />
    </a>
    <p style="font-size: 11px; line-height: 17px; margin: 0; padding: 0 4px 5px;">Follow us @starkpo.</p></div>

返回:

<img height="120" width="124" alt="Follow us @starkpo." style="border: 0;"
        src="http://www.thestarkingtonpost.com/wp-content/uploads/2009/09/twitter-master.jpg" 
        title="Join us on Twitter" />

    Follow us @starkpo.

预期的答案只是返回纯文本:关注我们@starkpo。

知道为什么它似乎忽略了自闭标签吗?

谢谢!

4

2 回答 2

1

您还需要告诉正则表达式引擎来.匹配换行符。

添加NSRegularExpressionDotMatchesLineSeparatorsoptions.

于 2012-02-22T03:47:39.980 回答
1

.默认情况下不匹配换行符。

NSRegularExpressionDotMatchesLineSeparators您可以使用标志启用此功能。

于 2012-02-22T03:48:38.497 回答