1. 去RegexKitLite下 载类库,解压出来会有一个例子包及2个文件,其实用到的就这2个文件,添加到工程中。

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的例子。

相关文章:

  • 2022-12-23
  • 2021-10-06
  • 2021-12-21
  • 2022-01-27
  • 2021-12-29
  • 2021-11-22
  • 2022-12-23
猜你喜欢
  • 2021-09-28
  • 2022-12-23
  • 2022-01-22
  • 2021-11-14
  • 2021-12-06
  • 2021-12-18
  • 2022-02-17
相关资源
相似解决方案