ObjectiveCVerbalExpressions

  • 所有者: VerbalExpressions/ObjectiveCVerbalExpressions
  • 平台:
  • 许可证: MIT License
  • 分类:
  • 主题:
  • 喜欢:
    0
      比较:

Github星跟踪图

ObjectiveCVerbalExpressions

version
platform
Build Status
Coverage Status

Objective-C Regular Expressions made easy

ObjectiveCVerbalExpressions is a Objective-C library that helps to construct difficult regular expressions - ported from the awesome JavaScript VerbalExpressions.

Installation

From Cocoapods

pod 'VEVerbalExpressions'

From source

Drags VerbalExpressions.h and VerbalExpressions.m into your projects and import "VerbalExpressions.h"

Examples

Here's a couple of simple examples to give an idea of how VerbalExpressions works:

Testing if we have a valid URL

// Create an example of how to test for correctly formed URLs
VerbalExpressions *tester = VerEx()
.startOfLine(YES)
.then(@"http")
.maybe(@"s")
.then(@"://")
.maybe(@"www")
.anythingBut(@" ")
.endOfLine(YES);

// Create an example URL
NSString *testMe = @"https://www.google.com";

// Use test() method
if (tester.test(testMe)) {
    NSLog(@"%@", @"We have a correct URL"); // This output will fire
} else {
    NSLog(@"%@", @"The URL is incorrect");
}

NSLog(@"%@", tester); // Ouputs the actual expression used: "^(http)(s)?(:�_/�_/)(www)?([^ ]*)$"

Replacing strings

NSString *replaceMe = @"Replace bird with a duck";

// Create an expression that seeks for word "bird"
VerbalExpressions *verEx = VerEx().find(@"bird");

// Execute the expression like a normal RegExp object
NSString *result = verEx.replace(replaceMe, @"duck" );

NSLog(@"%@", result); // Outputs "Replace duck with a duck"

Shorthand for string replace:

NSString *result2 = VerEx().find(@"red").replace(@"We have a red house", @"blue");

NSLog(@"%@", result2); // Outputs "We have a blue house"

API documentation

I haven't added much documentation to this repo yet, but you can find the documentation for the original JavaScript repo on their wiki. Most of the methods have been ported as of v0.1.0 of the JavaScript repo. Just be sure to use the syntax explained above rather than the dot notation :)

Contributions

Clone the repo and fork!
Pull requests are warmly welcomed!

Issues

  • I haven't yet ported the stopAtFirst method.

Thanks!

Thank you to @jehna for coming up with the awesome original idea!

Other implementations

You can view all implementations on VerbalExpressions.github.io

主要指标

概览
名称与所有者VerbalExpressions/ObjectiveCVerbalExpressions
主编程语言Objective-C
编程语言Objective-C (语言数: 2)
平台
许可证MIT License
所有者活动
创建于2013-08-10 08:31:55
推送于2018-09-21 23:46:10
最后一次提交2013-08-15 01:33:13
发布数3
最新版本名称v0.1.2 (发布于 )
第一版名称v0.1.0 (发布于 )
用户参与
星数286
关注者数28
派生数20
提交数41
已启用问题?
问题数0
打开的问题数0
拉请求数3
打开的拉请求数2
关闭的拉请求数0
项目设置
已启用Wiki?
已存档?
是复刻?
已锁定?
是镜像?
是私有?