Re: [Regexkit-discussion] Regex string results in an infinite loop
Status: Beta
Brought to you by:
jengelhart
From: John E. <joh...@gm...> - 2009-03-17 18:38:36
|
On Sat, Mar 14, 2009 at 6:51 PM, Aaron Warner <pap...@gm...> wrote: > 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); > } > } This is a bug in RegexKit.framework <= 0.6. It's a rather simple fix if you're willing to edit the sources. The problem, and a fix, is covered in the following forum message: http://sourceforge.net/forum/forum.php?thread_id=2660738&forum_id=731002 There is also a bug opened on this issue as well: http://sourceforge.net/tracker/index.php?func=detail&aid=1958025&group_id=204582&atid=990188 I really should get around to patching up this and a few other miscelanous bugs in RegexKit.framework, I just haven't gotten around to it. Most of my effort has been on RegexKitLite (which uses the system supplied ICU regex matcher, not PCRE) because it's fairly popular with iPhone developers (much smaller size since the system supplies the regex matcher in a shared library, and no apple imposed 'no external frameworks' limitations). |