match = isolate->factory()->NewSubString(subject,
match_start,
match_end);
- first = false;
}
elements->set(0, *match);
for (int i = 1; i <= capture_count; i++) {
if (start >= 0) {
int end = current_match[i * 2 + 1];
ASSERT(start <= end);
- Handle<String> substring =
- isolate->factory()->NewProperSubString(subject, start, end);
+ Handle<String> substring;
+ if (!first) {
+ substring =
+ isolate->factory()->NewProperSubString(subject, start, end);
+ } else {
+ substring =
+ isolate->factory()->NewSubString(subject, start, end);
+ }
elements->set(i, *substring);
} else {
ASSERT(current_match[i * 2 + 1] < 0);
elements->set(capture_count + 2, *subject);
builder->Add(*isolate->factory()->NewJSArrayWithElements(elements));
}
+ first = false;
}
// If we did not get the maximum number of matches, we can stop here
return match.length - 7;
});
assertEquals("4, 2!", str);
+
+// Test capture that is a real substring.
+var str = "Beasts of England, beasts of Ireland";
+str = str.replace(/(.*)/g, function(match) { return '~'; });
+assertEquals("~~");