iphone中使用第三方工具(RegexKitLite)实现正则表达式

来源:互联网 发布:ip地址查询域名 编辑:程序博客网 时间:2024/05/12 16:15
1.去RegexKitLite下载类库,解压出来会有一个例子包及2个文件,其实用到的就这2个文件,添加到工程中。
备用地址:
http://www.cocoachina.com/bbs/job.php?action-download-pid-135286-tid-18111-aid-11143.html
- Lv

2.工程中添加libicucore.dylib frameworks。

3.现在所有的nsstring对象就可以调用RegexKitLite中的方法了。

NSString *email = @”kkk@aaa.com”;

[email isMatchedByRegex:@"\\b([a-zA-Z0-9%_.+\\-]+)@([a-zA-Z0-9.\\-]+?\\.[a-zA-Z]{2,6})\\b”];

返回YES,证明是email格式,需要注意的是RegexKitLite用到的正则表达式和wiki上的略有区别。

searchString = @”http://www.example.com:8080/index.html”;

regexString  = @”\\bhttps?://[a-zA-Z0-9\\-.]+(?::(\\d+))?(?:(?:/[a-zA-Z0-9\\-._?,'+\\&%$=~*!():@\\\\]*)+)?”;

NSInteger portInteger = [[searchString stringByMatching:regexString capture:1L] integerValue];

NSLog(@”portInteger: ‘%ld’”, (long)portInteger);

// 2008-10-15 08:52:52.500 host_port[8021:807] portInteger: ‘8080′
取string中http的例子。
1.去RegexKitLite下载类库,解压出来会有一个例子包及2个文件,其实用到的就这2个文件,添加到工程中。
备用地址:
http://www.cocoachina.com/bbs/job.php?action-download-pid-135286-tid-18111-aid-11143.html
- Lv

2.工程中添加libicucore.dylib frameworks。

3.现在所有的nsstring对象就可以调用RegexKitLite中的方法了。

NSString *email = @”kkk@aaa.com”;

[email isMatchedByRegex:@"\\b([a-zA-Z0-9%_.+\\-]+)@([a-zA-Z0-9.\\-]+?\\.[a-zA-Z]{2,6})\\b”];

返回YES,证明是email格式,需要注意的是RegexKitLite用到的正则表达式和wiki上的略有区别。

searchString = @”http://www.example.com:8080/index.html”;

regexString  = @”\\bhttps?://[a-zA-Z0-9\\-.]+(?::(\\d+))?(?:(?:/[a-zA-Z0-9\\-._?,'+\\&%$=~*!():@\\\\]*)+)?”;

NSInteger portInteger = [[searchString stringByMatching:regexString capture:1L] integerValue];

NSLog(@”portInteger: ‘%ld’”, (long)portInteger);

// 2008-10-15 08:52:52.500 host_port[8021:807] portInteger: ‘8080′
取string中http的例子。
1.去RegexKitLite下载类库,解压出来会有一个例子包及2个文件,其实用到的就这2个文件,添加到工程中。
备用地址:
http://www.cocoachina.com/bbs/job.php?action-download-pid-135286-tid-18111-aid-11143.html
- Lv

2.工程中添加libicucore.dylib frameworks。

3.现在所有的nsstring对象就可以调用RegexKitLite中的方法了。

NSString *email = @”kkk@aaa.com”;

[email isMatchedByRegex:@"\\b([a-zA-Z0-9%_.+\\-]+)@([a-zA-Z0-9.\\-]+?\\.[a-zA-Z]{2,6})\\b”];

返回YES,证明是email格式,需要注意的是RegexKitLite用到的正则表达式和wiki上的略有区别。

searchString = @”http://www.example.com:8080/index.html”;

regexString  = @”\\bhttps?://[a-zA-Z0-9\\-.]+(?::(\\d+))?(?:(?:/[a-zA-Z0-9\\-._?,'+\\&%$=~*!():@\\\\]*)+)?”;

NSInteger portInteger = [[searchString stringByMatching:regexString capture:1L] integerValue];

NSLog(@”portInteger: ‘%ld’”, (long)portInteger);

// 2008-10-15 08:52:52.500 host_port[8021:807] portInteger: ‘8080′
取string中http的例子。
iphone中使用第三方工具(RegexKitLite)实现正则表达式

iphone中使用第三方工具(RegexKitLite)实现正则表达式
iphone中使用第三方工具(RegexKitLite)实现正则表达式
iphone中使用第三方工具(RegexKitLite)实现正则表达式

iphone中使用第三方工具(RegexKitLite)实现正则表达式

原创粉丝点击