首页 > 其他分享 >[IOS]开源库RegexKitLite正则表达式的使用

[IOS]开源库RegexKitLite正则表达式的使用

时间:2023-06-11 12:35:42浏览次数:53  
标签:RegexKitLite character IOS times 开源 Match input position match


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官网上的,怕同鞋偷情不看)
 
 
Description 
 
 
 
Match a BELL, \u0007 
 
 
 
Match at the beginning of the input. Differs from ^ in that \A will not match after a new-line within the input. 
 
 
 
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 
 
 
 
Match a BACKSPACE, \u0008. 
 
 
 
Match if the current position is not a word boundary. 
 
 
 
Match a Control-x character. 
 
 
 
Match any character with the Unicode General Category of Nd (Number, Decimal Digit). 
 
 
 
Match any character that is not a decimal digit. 
 
 
 
Match an ESCAPE, \u001B. 
 
 
 
Terminates a \Q…\E quoted sequence. 
 
 
 
Match a FORM FEED, \u000C. 
 
 
 
Match if the current position is at the end of the previous match. 
 
 
 
Match a LINE FEED, \u000A. 
 
 
 
Match the named Unicode Character. 
 
 
 
Match any character with the specified Unicode Property. 
 
 
 
Match any character not having the specified Unicode Property. 
 
 
 
Quotes all following characters until \E. 
 
 
 
Match a CARRIAGE RETURN, \u000D. 
 
 
 
Match a white space character. White space is defined as [\t\n\f\r\p{Z}]. 
 
 
 
Match a non-white space character. 
 
 
 
Match a HORIZONTAL TABULATION, \u0009. 
 
 
 
Match the character with the hex value hhhh. 
 
 
 
Match the character with the hex value hhhhhhhh. Exactly eight hex digits must be provided, even though the largest Unicode code point is \U0010ffff. 
 
 
 
Match a word character. Word characters are [\p{Ll}\p{Lu}\p{Lt}\p{Lo}\p{Nd}]. 
 
 
 
Match a non-word character. 
 
 
 
Match the character with hex value hhhh. From one to six hex digits may be supplied. 
 
 
 
Match the character with two digit hex value hh. 
 
 
 
Match a Grapheme Cluster. 
 
 
 
Match if the current position is at the end of input, but before the final line terminator, if one exists. 
 
 
 
Match if the current position is at the end of input. 
 
 
 
Back 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. 
 
 
 
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 * ? + [ ( ) { } ^ $ | \ . / 
 
 
 
Description 
 
 
 
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. 
 
 
 
Match exactly n times. 
 
 
 
Match at least n times. Match as many times as possible. 
 
 
 
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. 
 
 
 
Match exactly n times. 
 
 
 
Match at least n times, but no more than required for an overall pattern match. 
 
 
 
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. 
 
 
 
Match exactly n times. Possessive match. 
 
 
 
Match at least n times. Possessive match. 
 
 
 
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). 
 
 
 
Flag settings. Evaluate the parenthesized expression with the specified flags enabled or -disabled. 
 
 
 
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测试支持,可能下载的时候有点慢,耐心等待,链接


标签:RegexKitLite,character,IOS,times,开源,Match,input,position,match
From: https://blog.51cto.com/dingxiaowei/6457409

相关文章

  • cedar amazon 开源的安全框架
    cedaramazon开源的安全框架,包含了指南,一个基于rust的实现(当然还包含了一些其他语言的binding)目前已经提供了RBAC以及ABAC能力,casbin是一个比较类似的东西,功能点是有一些差异,是一个值得看看学习的项目参考资料https://aws.amazon.com/cn/blogs/opensource/using-open-source-c......
  • Fedora 开发者 Neal Gompa 计划在 x86 BIOS 系统上使用 U-Boot
    导读去年,Fedora和RedHat开发人员计划在Fedora37中放弃传统BIOS支持,只关注UEFI平台。但该计划随后遭到用户极力反对,认为现在弃用传统BIOS支持为时尚早,希望Fedora能够给出一个更加平缓的过渡方式。其次,一些云厂商仍在BIOS模式下启动VM,尤其是AWS和较小的......
  • 开源协议专题(六):GPL、LGPL、MPL
    背景说明:对于软件开发者来说,无论是个人还是商业组织,为了分享自己的优秀作品、为了扩大自身影响力,多多少少都有想把自己的软件作品以开源的形式公之于众的想法。但无论是开源自己的软件,还是使用已开源的软件,出于商业和法律因素的考虑,我们都应该搞清楚:当我们使用开源软件或者将自己......
  • 开源协议专题(五):开源协议的几个关键概念
    背景说明:本文主要讲述和开源协议相关的几个关键概念,方便后续介绍几个主流的开源协议以及比较他们之间的差异时能更好的理解。一、License:1、License:许可协议,也叫许可证。2、OpenSourceLicense:开源许可证,或者叫开源许可协议,是指开源组织为了维护作者和贡献者的合法权利,保证......
  • 开源协议专题(四):最早的开源基金会和组织
    回顾全球开源运动和开源社区的发展历程可以看出,开源基金会对于开源软件和开源社区的组织、发展、协同创新提供了主导作用。开源基金会遵循公开、透明、开放等理念,为开源软件的孵化提供技术、运营、法律等全方位支持,为开源的社区建设和运营提供指导,发挥了孵化器和加速器的作用,开源......
  • 开源协议专题(一):计算机和操作系统发展史
    一、电子计算机发展史:从上世纪40年代起,人类开始研究并创造了计算机,从体型庞大功能简单的计算机,到超大规模集成电路的超级计算机;从简单的控制操作流程的程序,到多用户多任务多处理器架构的操作系统;短短半个世纪,人类在电子计算机科学领域,经历了创世纪历程,并以指数级速度发展(摩尔定......
  • 开源协议专题(二):开源之父和 GUN 计划
    在计算机这个人类智慧结晶的创世纪过程中,随着操作系统从无到有、随着层出不穷的软件被创造出来,版权、相关领域的垄断及法律也随之出现,开源软件运动和开源许可协议也随之出现。在软件开源的运动发展过程中,涌现出了很多动人的故事,新的概念如开源软件、开源许可协议、开源系统等,如同......
  • 使用axios 请求后端
    1、使用CDN的方式导入axios点击查看代码<scriptsrc="https://unpkg.com/axios/dist/axios.min.js"></script>二,跨域问题的解决1,什么是跨域CORS,全称是:Cross-OriginResourceShareing2,跨域问题的解决后端增加全局的过滤器三,前端elementUI点击查看代码<!--引......
  • 业余开源项目训练出最准确新冠预测机器学习模型
    什么样的机器学习项目会被美国疾控中心CDC、纽约时报、经济学人杂志等多家机构和媒体所引用提及,还被Facebook的ChiefAIExecutor称为最准确的新冠死亡预测模型?这就是今天要给大家分享的covid-projection——一个来自一名普通美国华裔数据科学家的的业余开源机器学习项目。covid-......
  • 业余开源项目训练出最准确新冠预测机器学习模型
    什么样的机器学习项目会被美国疾控中心CDC、纽约时报、经济学人杂志等多家机构和媒体所引用提及,还被Facebook的ChiefAIExecutor称为最准确的新冠死亡预测模型?这就是今天要给大家分享的covid-projection——一个来自一名普通美国华裔数据科学家的的业余开源机器学习项目。covid......