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

友情提醒:一般人导入RegexKitLite编译报错,正是因为没有导入这个类库,加上这个就OK了

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

下面给出常用的一些正则表达式(其实就是RegexKitLite官网上的,怕同鞋偷情不看)

CharacterDescription
\aMatch a BELL, \u0007
\AMatch at the beginning of the input. Differs from ^ in that \A will not match after a new-line within the input.
\b, outside of a [Set]Match if the current position is a word boundary. Boundaries occur at the transitions between word \w and non-word \W characters, with combining marks ignored.
See also: RKLUnicodeWordBoundaries
\b, within a [Set]Match a BACKSPACE, \u0008.
\BMatch if the current position is not a word boundary.
\cxMatch a Control-x character.
\dMatch any character with the Unicode General Category of Nd (Number, Decimal Digit).
\DMatch any character that is not a decimal digit.
\eMatch an ESCAPE, \u001B.
\ETerminates a \Q…\E quoted sequence.
\fMatch a FORM FEED, \u000C.
\GMatch if the current position is at the end of the previous match.
\nMatch a LINE FEED, \u000A.
\N{Unicode Character Name}Match the named Unicode Character.
\p{Unicode Property Name}Match any character with the specified Unicode Property.
\P{Unicode Property Name}Match any character not having the specified Unicode Property.
\QQuotes all following characters until \E.
\rMatch a CARRIAGE RETURN, \u000D.
\sMatch a white space character. White space is defined as [\t\n\f\r\p{Z}].
\SMatch a non-white space character.
\tMatch a HORIZONTAL TABULATION, \u0009.
\uhhhhMatch the character with the hex value hhhh.
\UhhhhhhhhMatch the character with the hex value hhhhhhhh. Exactly eight hex digits must be provided, even though the largest Unicode code point is \U0010ffff.
\wMatch a word character. Word characters are [\p{Ll}\p{Lu}\p{Lt}\p{Lo}\p{Nd}].
\WMatch a non-word character.
\x{h…}Match the character with hex value hhhh. From one to six hex digits may be supplied.
\xhhMatch the character with two digit hex value hh.
\XMatch a Grapheme Cluster.
\ZMatch if the current position is at the end of input, but before the final line terminator, if one exists.
\zMatch if the current position is at the end of input.
\nBack Reference. Match whatever the nth capturing group matched. n must be a number ≥ 1 and ≤ total number of capture groups in the pattern.Note:Octal escapes, such as \012, are not supported.
[pattern]Match any one character from the set. See ICU Regular Expression Character Classes for a full description of what may appear in the pattern.
.Match any character.
^Match at the beginning of a line.
$Match at the end of a line.
\Quotes the following character. Characters that must be quoted to be treated as literals are * ? + [ ( ) { } ^ $ | \ . /
OperatorsOperatorDescription
|Alternation. A|B matches either A or B.
*Match zero or more times. Match as many times as possible.
+Match one or more times. Match as many times as possible.
?Match zero or one times. Prefer one.
{n}Match exactly n times.
{n,}Match at least n times. Match as many times as possible.
{n,m}Match between n and m times. Match as many times as possible, but not more than m.
*?Match zero or more times. Match as few times as possible.
+?Match one or more times. Match as few times as possible.
??Match zero or one times. Prefer zero.
{n}?Match exactly n times.
{n,}?Match at least n times, but no more than required for an overall pattern match.
{n,m}?Match between n and m times. Match as few times as possible, but not less than n.
*+Match zero or more times. Match as many times as possible when first encountered, do not retry with fewer even if overall match fails. Possessive match.
++Match one or more times. Possessive match.
?+Match zero or one times. Possessive match.
{n}+Match exactly n times. Possessive match.
{n,}+Match at least n times. Possessive match.
{n,m}+Match between n and m times. Possessive match.
(…)Capturing parentheses. Range of input that matched the parenthesized subexpression is available after the match.
(?:…)Non-capturing parentheses. Groups the included pattern, but does not provide capturing of matching text. Somewhat more efficient than capturing parentheses.
(?>…)Atomic-match parentheses. First match of the parenthesized subexpression is the only one tried; if it does not lead to an overall pattern match, back up the search for a match to a position before the (?> .
(?#…)Free-format comment (?#comment).
(?=…)Look-ahead assertion. True if the parenthesized pattern matches at the current input position, but does not advance the input position.
(?!…)Negative look-ahead assertion. True if the parenthesized pattern does not match at the current input position. Does not advance the input position.
(?<=…)Look-behind assertion. True if the parenthesized pattern matches text preceding the current input position, with the last character of the match being the input character just before the current position. Does not alter the input position. The length of possible strings matched by the look-behind pattern must not be unbounded (no * or + operators).
(?<!…)Negative Look-behind assertion. True if the parenthesized pattern does not match text preceding the current input position, with the last character of the match being the input character just before the current position. Does not alter the input position. The length of possible strings matched by the look-behind pattern must not be unbounded (no * or + operators).
(?ismwx-ismwx:…)Flag settings. Evaluate the parenthesized expression with the specified flags enabled or -disabled.
(?ismwx-ismwx)Flag settings. Change the flag settings. Changes apply to the portion of the pattern following the setting. For example, (?i) changes to a case insensitive match.
See also: Regular Expression Options

同时需要注意的是转义字符哦~~在safari上复制会直接转换(网站蛮人性化的)

同时也提供了转换工具,safari测试支持,可能下载的时候有点慢,耐心等待,链接

本文转蓬莱仙羽51CTO博客,原文链接:http://blog.51cto.com/dingxiaowei/1366248,如需转载请自行联系原作者

[IOS]开源库RegexKitLite正则表达式的使用相关推荐

  1. 33个2017年必须了解的iOS开源库

    原文 本文翻译自Medium,原作者为 Paweł Białecki 照片版权:(Unsplash/Markus Pe) 你好,iOS 开发者们!我的名字叫 Paweł,我是一个独立 iOS 开发者, ...

  2. fir.im Weekly - 2017 年必须了解的 iOS 开源库

    放假的脚步临近,每个人都在期待一个愉悦的春节假期.最近,@张嘉夫 分享了一篇 Medium 上的文章<33 个 2017 年必须了解的 iOS 开源库>,总结了 2016 年最棒的 iOS ...

  3. 27个iOS开源库,让你的开发坐上火箭吧

    本文翻译自Medium,原作者是Paweł Białecki,原文 27个iOS开源库,让你的开发坐上火箭吧 你不会想错过他们,真的. 我爱开源. 并且我喜欢开发者们,把他们宝贵的私人时间用来创造神奇 ...

  4. 33 个 2017 年必须了解的 iOS 开源库

    你好,iOS 开发者们!我的名字叫 Paweł,我是一个独立 iOS 开发者,并且是 Enter Universe 的作者. 接近两年前我发布了 27 个iOS开源库,让你的开发坐上火箭吧.这是我在这 ...

  5. ios开发——27个iOS开源库,让你的开发坐上火箭吧

    本文翻译自Medium,原作者是Paweł Białecki,原文 27个iOS开源库,让你的开发坐上火箭吧 你不会想错过他们,真的. 我爱开源. 并且我喜欢开发者们,把他们宝贵的私人时间用来创造神奇 ...

  6. iOS开源库PKRevealController的使用

    2019独角兽企业重金招聘Python工程师标准>>> 自学iOS也有一段时间了,期间发现iOS和Android一样,有很多非常优秀的开源库可以使用.但无奈国内几乎没有太多关于此方面 ...

  7. 27个提升效率的iOS开源库推荐

    2019独角兽企业重金招聘Python工程师标准>>> 我热爱开源,更喜爱那些花费宝贵的业余时间来创造奇迹的开发者们,感谢他们将自己辛苦劳动的成果无偿分享给大家.开源作者和贡献者们, ...

  8. 10个有用的第三方iOS开源库

    CocoaPods 地址:https://github.com/CocoaPods/CocoaPods 教程:http://www.raywenderlich.com/12139/introducti ...

  9. 33 个 2017 年必须了解的 iOS 开源库(包含swift)

    1.IGListKit,作者是Instagram Engineering Instagram 程序员做的,IGListKit 是数据驱动的 UICollectionView 框架,为了构建快速和可扩展 ...

最新文章

  1. Spring Boot 集成Swagger2生成RESTful API文档
  2. android加载时二级联动点击二级联动,Android实现联动下拉框二级地市联动下拉框功能...
  3. iphone修改html样式,html – iphone在输入上覆盖我的所有样式[type =“submit”]
  4. struts2 如何跳转html5,在线HTML编辑器——ueditor,跟struts2结合
  5. 在Windows64位环境下.net访问Oracle解决方案(转)
  6. 《深入理解Java虚拟机》读书笔记3--垃圾回收算法
  7. 前端学习(1847)vue之电商管理系统电商系统的功能划分
  8. 【转载】ADS分散加载文件使用总结(lpc23xx)
  9. 【Elasticsearch】Elasticsearch 7 : 动态映射 dynamic
  10. 30岁女IT工程师感叹:靠这工具,把报表做成养老工作,月薪快3W
  11. vc java动态库_Java调用已经写好的VC++动态链接库
  12. 如何救队友_PS4《高达EXVSMBON》:如何违抗拥有巴力的他?
  13. maven 打包父工程_maven 父子工程打包 并且上传linux服务器
  14. block才会执行 mono_Monogb基本概念及基本操作
  15. mysql join 主表唯一_mysql left join 右表数据不唯一的情况解决方法
  16. wp8.1 java,Windows Phone 粉的福音:如何给 WP8.1 解锁部署 xap 软件
  17. php 包含因子,轻松掌握测量不确定度——(4)测量不确定度的评定和报告(完)...
  18. python网页教程_python网页教程
  19. matlab中的全局参量,matlab参数传递及全局变量 | 学步园
  20. 《项目》 之 ESP8266 心知天气 + 时钟 + WS2812点阵屏 + B站粉丝计数

热门文章

  1. python解题_python实现用户答题功能
  2. java 返回第k小的数_java – 给定n和k,返回第k个置换序列
  3. cnn神经网络_神经网络之CNN和RNN
  4. 同一列两行数据怎么合并成一行_经常加班怎么办?两分钟学会这4招,让同事刮目相看!...
  5. c# list集合根据某个字段去重_java8 List 根据对象某个字段或多个字段去重、筛选、List转Map、排序、分组、统计计数等等...
  6. 计算机项目教学法探讨,项目教学法在计算机教学中应用计算机教学论文计算机论文...
  7. java数组复制_Java自学-数组 复制数组
  8. linux中python编译器的配置_方舟编译器环境配置及源码编译过程详解
  9. Maven项目设置仓库下载位置
  10. 【codevs30123037】线段覆盖4、5,姗姗来迟