VerbalExpressions 是一个 Objective C 库,它帮助构建复杂的正则表达式。
VerbalExpressions 需要iOS >= 4.3 或 Mac OS >= 10.7。它还使用 ARC。
将 VerbalExpressions.h
和 VerbalExpressions.m
拖入您的项目,并使用 import "VerbalExpressions.h"
导入
// url matches
VerbalExpressions *tester = [[[[[[[[VerEX() startOfLine] then:@"http"] maybe:@"s"] then:@"://"] maybe:@"www."] anythingBut:@" "] range:@[@"a",@"e"]] endOfLine];
NSString *testMe = @"https://www.google.com/";
if( [tester test:testMe] ){
NSLog(@"We have a correct URL ");
}else{
NSLog(@"The URL is incorrect");
}
// replace string
NSString *replaceMe = @"Replace bird with a duck";
tester = [VerEX() find:@"bird"];
NSString *result = [tester replace:replaceMe by:@"duck"];
NSLog(@"result = %@",result);
// shorthand for string replace
result = [[VerEX() find:@"red"] replace:@"We have a red house" by:@"blue"];
NSLog(@"result = %@",result);