朱海文 3e28daaec5 init | 3 years ago | |
---|---|---|
.. | ||
LICENSE.txt | 3 years ago | |
RegExCategories.h | 3 years ago | |
RegExCategories.m | 3 years ago | |
readme.md | 3 years ago |
This project is a collection of objective-c categories for NSRegularExpression and NSString that make usage easier and more concise. For example:
//Using NSRegularExpression
NSString* string = @"I have 2 dogs.";
NSRegularExpression *regex = [NSRegularExpression regular ExpressionWithPattern:@"\\d+" options:NSRegularExpressionCaseInsensitive error:&error];
NSTextCheckingResult *match = [regex firstMatchInString:string options:0 range:NSMakeRange(0, [string length])];
BOOL isMatch = match != nil;
// Using this library
BOOL isMatch = [@"I have 2 dogs." isMatch:RX(@"\\d+")];
This library has no dependencies and works for iOS4+ and OSX v10.7+.
To install it, just copy these two files into your project:
You may want to add it to your Prefix.pch so that is is available across your code base.
#ifdef __OBJC__
/* ...other references... */
#import "RegExCategories.h"
#endif
You also need to have ARC enabled on your XCode project. If you don't then add the -fobjc-arc
flag on Objective-C-Regex-Categories.m
under Targets > Build Phases > Compile Sources (more info here).
If you need help, submit an issue, send a pull request, or tweet at me @BendyTree.
MIT License - do whatever you want, just (1) provide attribution and (2) don't hold me liable.
This repository includes unit tests written in the XCTest framework. These test are automatically verified using Travis-CI. Here is the current status: