<?xml version="1.0" encoding="utf-8"?>
<feed xml:lang="en" xmlns="http://www.w3.org/2005/Atom"><title>Recent changes to 58: captureComponents on empty string inconsistent</title><link href="https://sourceforge.net/p/regexkit/bugs/58/" rel="alternate"/><link href="https://sourceforge.net/p/regexkit/bugs/58/feed.atom" rel="self"/><id>https://sourceforge.net/p/regexkit/bugs/58/</id><updated>2010-12-30T02:16:44Z</updated><subtitle>Recent changes to 58: captureComponents on empty string inconsistent</subtitle><entry><title>captureComponents on empty string inconsistent</title><link href="https://sourceforge.net/p/regexkit/bugs/58/" rel="alternate"/><published>2010-12-30T02:16:44Z</published><updated>2010-12-30T02:16:44Z</updated><author><name>Brian Schack</name><uri>https://sourceforge.net/u/bjschack/</uri></author><id>https://sourceforge.nete3130bb9f49328a9128251ed75f1fc445d1644f1</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;If an empty string invokes captureComponentsMatchedByRegex, the results should be an array of empty strings (one for each component, plus one for the entire match).  However, the following code reports that out of 1000 iterations, the capture array is empty 500 times, and has two elements the other 500 times.&lt;/p&gt;
&lt;p&gt;int iterations = 1000;&lt;br /&gt;
int empties = 0, twos = 0;&lt;br /&gt;
for (int i = 0; i &amp;lt; iterations; i++) {&lt;br /&gt;
NSString *exp = @"";&lt;br /&gt;
NSString *regex = @"( *)";&lt;br /&gt;
NSArray *matches = [exp captureComponentsMatchedByRegex:regex];&lt;br /&gt;
if ([matches count] == 0) {&lt;br /&gt;
empties++;&lt;br /&gt;
} else if ([matches count] == 2) {&lt;br /&gt;
twos++;&lt;br /&gt;
}&lt;br /&gt;
}&lt;br /&gt;
NSLog(@"%d empties, %d twos out of %d iterations", empties, twos, iterations);&lt;/p&gt;&lt;/div&gt;</summary></entry></feed>