1.去RegexKitLite下载类库,解压出来会有一个例子包及2个文件,其实用到的就这2个文件,添加到工程中。
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测试支持,可能下载的时候有点慢,耐心等待,链接
- Linq之旅:Linq入门详解(Linq to Objects)
示例代码下载:Linq之旅:Linq入门详解(Linq to Objects) 本博文详细介绍 .NET 3.5 中引入的重要功能:Language Integrated Query(LINQ,语言集 ...
- 架构设计:远程调用服务架构设计及zookeeper技术详解(下篇)
一.下篇开头的废话 终于开写下篇了,这也是我写远程调用框架的第三篇文章,前两篇都被博客园作为[编辑推荐]的文章,很兴奋哦,嘿嘿~~~~,本人是个很臭美的人,一定得要截图为证: 今天是2014年的第一天 ...
- EntityFramework Core 1.1 Add、Attach、Update、Remove方法如何高效使用详解
前言 我比较喜欢安静,大概和我喜欢研究和琢磨技术原因相关吧,刚好到了元旦节,这几天可以好好学习下EF Core,同时在项目当中用到EF Core,借此机会给予比较深入的理解,这里我们只讲解和EF 6. ...
- Java 字符串格式化详解
Java 字符串格式化详解 版权声明:本文为博主原创文章,未经博主允许不得转载. 微博:厉圣杰 文中如有纰漏,欢迎大家留言指出. 在 Java 的 String 类中,可以使用 format() 方法 ...
- Android Notification 详解(一)——基本操作
Android Notification 详解(一)--基本操作 版权声明:本文为博主原创文章,未经博主允许不得转载. 微博:厉圣杰 源码:AndroidDemo/Notification 文中如有纰 ...
- Android Notification 详解——基本操作
Android Notification 详解 版权声明:本文为博主原创文章,未经博主允许不得转载. 前几天项目中有用到 Android 通知相关的内容,索性把 Android Notificatio ...
- Git初探--笔记整理和Git命令详解
几个重要的概念 首先先明确几个概念: WorkPlace : 工作区 Index: 暂存区 Repository: 本地仓库/版本库 Remote: 远程仓库 当在Remote(如Github)上面c ...
- Drawable实战解析:Android XML shape 标签使用详解(apk瘦身,减少内存好帮手)
Android XML shape 标签使用详解 一个android开发者肯定懂得使用 xml 定义一个 Drawable,比如定义一个 rect 或者 circle 作为一个 View 的背景. ...
- Node.js npm 详解
一.npm简介 安装npm请阅读我之前的文章Hello Node中npm安装那一部分,不过只介绍了linux平台,如果是其它平台,有前辈写了更加详细的介绍. npm的全称:Node Package M ...
随机推荐
- android 程序打开第三方程序
因为在开发过程中需要开启扫描第三方程序,并且点击启动的效果,所以对这个功能进行了实现,并且分享出来个大家. 之前看到网上说需要获取包名和类名,然后通过 intent 才能打开这个程序,其实不必要这样 ...
- arcgis python 获得所有的工具名称
#######################import arcgisscripting import string; gp = arcgisscripting.create(9.3); ### ...
- arcgis通过 Python 使用工具 获得结果信息
通过 Python 使用工具 ArcGIS 10 每个地理处理工具都具有一组固定的参数,这些参数为工具提供执行所需的信息.工具通常具有定义一个或多个数据集的输入参数,这些数据集一般用于生成新的输出数据 ...
- 重载public Primes ():this(2,100)
当构造函数有多个重载的时候 想通过默认构造函数调用其他的重载的构造函数的话 就可以用:运算符public Primes():this(2, 100){//code }public Primes(int ...
- easyui-textbox
TextBox 扩展自 $.fn.validatebox.defaults. 重写 $.fn.textbox.defaults. TextBox 是加强的输入控件,使我们建设表单更加快捷. 是一些复杂 ...
- 图解I/O的五种模型
1.1 五种I/O模型 1)阻塞I/O 2)非阻塞I/O 3)I/O复用 4)事件(信号)驱动I/O 5)异步I/O 1.2 为什么要发起系统调用? 因为进程想要获取磁盘中的数据,而能和磁盘打交道的只 ...
- Redis与Memcached对比
Redis是一种高级key-value数据库.它跟memcached类似,不过数据可以持久化,而且支持的数据类型很丰富,有字符串.链表.集合和有序集合.支持在服务器端计算集合的并,交和补集等.还支持多 ...
- 幻灯片の纯CSS,NO JavaScript
之前就遇到有人问,不用js,纯css实现幻灯片. 那么对于使用纯的css + html 怎样来实现幻灯片呢?下面有几种方法可供参考,有些还不成熟. 方案一:利用css3的animation 例子传送门 ...
- CSS3 动画效果合集
@charset "UTF-8"; /*! * animate.css -http://daneden.me/animate * Version - 3.5.1 * License ...
- CAS 单点登录,通过ticket 获取登录用户
string url =SSOValidate+"?service=" + WebValidate + "&ticket=" + Ticket + &q ...