[Regexkit-discussion] Regex string results in an infinite loop
Status: Beta
Brought to you by:
jengelhart
|
From: Aaron W. <pap...@gm...> - 2009-03-14 22:51:36
|
Hello,
The following code block results in an infinite loop. The subject
string that is commented out, seems to work ok. I'have tried the same
expression on other engines without this problem. I should note that
this expression comes from the textmate c code bundle. Am I missing
anything here?
{
// capture preprocessor macro
NSString *regexString = @"(?ms)((?x)^\\s*\\#\\s*(define)\\s+((?<id>
[a-zA-Z_][a-zA-Z0-9_]*))(?:(\\()(\\s*\\g{id}\\s*((,)\\s*\\g{id}\\s*)*
(?:\\.\\.\\.)?)(\\)))?.*?(?=(?://|/\\*))|$)";
NSString *subjectString = @"/";
// NSString *subjectString = @"#define HELLO(a,b) hello(a,b) // say
hello";
NSUInteger matchCount = 0;
// make sure regexString doesn't cause an infinate loop
RKEnumerator *matchEnumerator = [subjectString
matchEnumeratorWithRegex:regexString];
while([matchEnumerator nextRanges] != NULL) {
matchCount++;
if(matchCount++ > 10) {
assert(0);
}
}
thanks,
kube |