奇数正则表达式结果... /字符

时间:2012-02-22 03:40:46

标签: objective-c regex nsregularexpression

我在objective-c

中有这个正则表达式
NSString* searchString = [searchBlock stringByReplacingOccurrencesOfString:@"<(.*?)>" withString:@"" options: NSRegularExpressionSearch range:NSMakeRange (0, [searchBlock length])];

代码应该删除尖括号之间的所有内容&lt;&gt;它似乎在大部分时间都有效,但似乎在这种情况下失败了,我不确定原因:

<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。

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

谢谢!

2 个答案:

答案 0 :(得分:1)

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

NSRegularExpressionDotMatchesLineSeparators添加到options

答案 1 :(得分:1)

默认情况下,

.与换行符不匹配。

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

相关问题