功能/库像iPhone编程中的preg_match_all(PHP) [英] Function/Library like preg_match_all(PHP) in iPhone programming

查看:97
本文介绍了功能/库像iPhone编程中的preg_match_all(PHP)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在搜索类似于PHP的preg_match_all(或类似)的函数。

I' m searching function that will works like preg_match_all (or similar) from for example PHP.

我想给出一个模式和我的NSData对象(带有HTML内容)然后获得适合模式的所有结果。

I want give a pattern and my NSData object(with HTML content) then get all results that fits to pattern.

我在编程iOS 5.是否有任何库或函数可以执行此操作?

I' m programming iOS 5. Is there any library or function to do this ?

推荐答案

看看 NSRegularExpression class。

这是一段使用它的代码片段:

Here's a snippet of code that uses it:


    NSError *error = nil;
    NSRegularExpression *tagsRegex = [NSRegularExpression 
         regularExpressionWithPattern:@"(<b>|<u>|<i>|<br/?>)" 
                              options:NSRegularExpressionCaseInsensitive
                                error:&error];
    if (!tagsRegex) {
        NSLog(@"Tags regex creation error: %@", [error localizedDescription]);
    }

    if ([tagsRegex numberOfMatchesInString:marketingMessage options:0 
                        range:NSMakeRange(0, [marketingMessage length])])
    {
        ...
    }

这篇关于功能/库像iPhone编程中的preg_match_all(PHP)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆