Menu

#68 Nondeterministic behavior when matching empty strings

RegexKitLite 4.0
open
nobody
None
5
2014-06-06
2014-06-06
David
No

When a regex matches an empty string, it returns "NO" every other call, even if the regex matches.

For example, "foo" in the following example will always be "NO", since "[emptyString isMatchedByRegex:regex]" will alternate return values on every call.

NSString* emptyString = @"";
NSString* regex       = @"^$";
BOOL foo = [emptyString isMatchedByRegex:regex] == [emptyString isMatchedByRegex:regex];

This only works when the regexes are identical, however. For instance:

BOOL bar = [emptyString isMatchedByRegex:@"^$"] == [emptyString isMatchedByRegex:@"^.*$"];

will normally be true, as both statements are likely to be in sync.

Since this technique is used in the "Parsing CSV Data" example, either the documentation or RegexKitLite is in need of an update.

OSX 10.9.2, XCode 5.0.2, 10.9 SDK, ARC off.

Discussion


Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.