2012-06-14 58 views
1

我有一個小問題,我使用一個代碼片段從iOS的字符串中刪除的html代碼:的iOS RangeOfString NSRegularExpressionSearch

while ((r = [s rangeOfString:@"<[^>]+>" options:NSRegularExpressionSearch]).location != NSNotFound) 
     s = [s stringByReplacingCharactersInRange:r withString:@""]; 

,現在我需要刪除一些塊,等等。爲什麼這段代碼不工作:

while ((r = [s rangeOfString:@"<style[^>]+style>" options:NSRegularExpressionSearch]).location != NSNotFound) 
    s = [s stringByReplacingCharactersInRange:r withString:@""]; 

感謝您的幫助!

+0

閱讀:http://stackoverflow.com/tags/regex/info除非你提供有關輸入更多的假設,它是更好地使用解析器做這項工作。 – nhahtdh

回答

0

試試這個:

while ((r = [s rangeOfString:@"<style[^>]+>[^>]+</style>" options:NSRegularExpressionSearch]).location != NSNotFound) { 
    s = [s stringByReplacingCharactersInRange:r withString:@""]; 

}

相關問題