(Created page with '{{occlass|library=AppSupport.framework}} CPRegularExpression is a wrapper around the POSIX [http://www.opengroup.org/onlinepubs/007908799/xsh/regex.h.html regex.h] library. …') |
(adding missing navbox) |
||
Line 26: | Line 26: | ||
== Header == | == Header == | ||
* http://github.com/kennytm/iphone-private-frameworks/blob/master/AppSupport/CPRegularExpression.h | * http://github.com/kennytm/iphone-private-frameworks/blob/master/AppSupport/CPRegularExpression.h | ||
{{occlass|library=AppSupport.framework|navbox=1}} |
Revision as of 00:35, 7 September 2013
CPRegularExpression is a wrapper around the POSIX regex.h library. Example use:
NSString* test = [NSString stringWithContentsOfFile:@"TestFile.txt"];
CPRegularExpression* re = [CPRegularExpression regularExpressionWithString:@"([-_[:alpha:]]+)=['\"]?([^'\">[:blank:]]*)['\"]?"];
NSRange curRange = NSMakeRange(0, [test length]);
NSUInteger subexprCount = [re numberOfSubexpressions];
NSRange subexprs[subexprCount];
while (1) {
NSRange newRange = [re matchedRangeForString:test range:curRange subexpressionRanges:subexprs count:subexprCount];
if (newRange.location == NSNotFound)
break;
else {
NSLog(@"%@ -> %@", [test substringWithRange:subexprs[0]], [test substringWithRange:subexprs[1]]);
// Changing the range alone is buggy.
test = [test substringFromIndex:newRange.location + newRange.length];
curRange.length = [test length];
}
}
Header
|