PDA

View Full Version : OFRegularExpression Queston


titaniumdecoy
09-30-2007, 07:46 PM
If I have the string "alphalpha" and create an OFRegularExpression with the regular expression "alpha", is there any way to match both "alpha"s in the aforementioned string? The OFRegularExpression seems to skip to the second "l" after matching the first "alpha"--is there any way to start at each letter rather than after each match? Thanks.

Greg Titus
10-01-2007, 09:33 PM
Hmm. This seems like a bug. Maybe we should change OFRegularExpressionMatch to fix it.

Meanwhile, the way that you could do it in your code is to use OFRegularExpression's -matchInString:range: method to loop through matches like so:

OFRegularExpression *expression; // the expression
NSString *string; // string searching through
NSRange searchRange = NSMakeRange(0, [string length]);
OFRegularExpressionMatch *match;

while ((match = [expression matchInString:string range:searchRange])) {
// do whatever you want with the match, then
searchRange.location = [match matchRange].location + 1;
searchRange.length = [string length] - searchRange.location;
}

Hope this helps!