RegexKitLite 使用详解

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

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

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

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

NSString *email = @”[email protected]”;

[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测试支持,可能下载的时候有点慢,耐心等待,链接

时间: 2024-09-15 13:08:42

RegexKitLite 使用详解的相关文章

iOS疯狂详解之CocoaPods做iOS程序包的依赖管理

每种语言发展到一个阶段,就会出现相应的依赖管理工具, 或者是中央代码仓库.比如 Java: maven,Ivy Ruby: gems Python: pip, easy_install Nodejs: npm 随着iOS开发者的增多,业界也出现了为iOS程序提供依赖管理的工具,这个工具叫:CocoaPods. CocoaPods简介 CocoaPods是一个负责管理iOS项目中第三方开源代码的工具.CocoaPods项目的源码在Github上管理.该项目开始于2011年8月12日,经过一年多的发

Spring事务管理(详解+实例)

写这篇博客之前我首先读了<Spring in action>,之后在网上看了一些关于Spring事务管理的文章,感觉都没有讲全,这里就将书上的和网上关于事务的知识总结一下,参考的文章如下: Spring事务机制详解 Spring事务配置的五种方式 Spring中的事务管理实例详解 1 初步理解 理解事务之前,先讲一个你日常生活中最常干的事:取钱. 比如你去ATM机取1000块钱,大体有两个步骤:首先输入密码金额,银行卡扣掉1000元钱:然后ATM出1000元钱.这两个步骤必须是要么都执行要么都

转载:DenseNet算法详解

原文连接:http://blog.csdn.net/u014380165/article/details/75142664 参考连接:http://blog.csdn.net/u012938704/article/details/53468483 本文这里仅当学习笔记使用,具体细节建议前往原文细度. 论文:Densely Connected Convolutional Networks 论文链接:https://arxiv.org/pdf/1608.06993.pdf 代码的github链接:h

MariaDB(MySQL)创建、删除、选择及数据类型使用详解

一.MariaDB简介(MySQL简介略过) MariaDB数据库管理系统是MySQL的一个分支,主要由开源社区在维护,采用GPL授权许可 MariaDB的目的是完全兼容MySQL,包括API和命令行,使之能轻松成为MySQL的代替品.在存储引擎方面,使用XtraDB(英语:XtraDB)来代替MySQL的InnoDB. MariaDB由MySQL的创始人Michael Widenius(英语:Michael Widenius)主导开发,他早前曾以10亿美元的价格,将自己创建的公司MySQL A

HttpServletResponse和HttpServletRequest详解

HttpServletResponse,HttpServletRequest详解 1.相关的接口 HttpServletRequest HttpServletRequest接口最常用的方法就是获得请求中的参数,这些参数一般是客户端表单中的数据.同时,HttpServletRequest接口可以获取由客户端传送的名称,也可以获取产生请求并且接收请求的服务器端主机名及IP地址,还可以获取客户端正在使用的通信协议等信息.下表是接口HttpServletRequest的常用方法. 说明:HttpServ

POSIX 线程详解(经典必看)

总共三部分: 第一部分:POSIX 线程详解                                   Daniel Robbins ([email protected]), 总裁/CEO, Gentoo Technologies, Inc.  2000 年 7 月 01 日 第二部分:通用线程:POSIX 线程详解,第 2部分       Daniel Robbins ([email protected]), 总裁/CEO, Gentoo Technologies, Inc.  20

.NET深入解析LINQ框架(五:IQueryable、IQueryProvider接口详解)

阅读目录: 1.环路执行对象模型.碎片化执行模型(假递归式调用) 2.N层对象执行模型(纵横向对比链式扩展方法) 3.LINQ查询表达式和链式查询方法其实都是空壳子 4.详细的对象结构图(对象的执行原理) 5.IQueryable<T>与IQueryProvider一对一的关系能否改成一对多的关系 6.完整的自定义查询 1]. 环路执行对象模型.碎片化执行模型(假递归式调用) 这个主题扯的可能有点远,但是它关系着整个LINQ框架的设计结构,至少在我还没有搞懂LINQ的本意之前,在我脑海里一直频

netstat状态详解

一.生产服务器netstat tcp连接状态................................................................................ 2 1.1生产服务器某个业务LVS负载均衡上连接状态数量............................................... 2 1.2生产服务器某个业务web上连接状态数量...............................................

详解go语言的array和slice 【二】

上一篇  详解go语言的array和slice [一]已经讲解过,array和slice的一些基本用法,使用array和slice时需要注意的地方,特别是slice需要注意的地方比较多.上一篇的最后讲解到创建新的slice时使用第三个索引来限制slice的容量,在操作新slice时,如果新slice的容量大于长度时,添加新元素依然后使源的相应元素改变.这一篇里我会讲解到如何避免这些问题,以及迭代.和做为方法参数方面的知识点. slice的长度和容量设置为同一个值 如果在创建新的slice时我们把