diff --git a/gb.pcre/src/regexp.c b/gb.pcre/src/regexp.c index 39f1402e7..5e1134ac0 100644 --- a/gb.pcre/src/regexp.c +++ b/gb.pcre/src/regexp.c @@ -393,18 +393,14 @@ BEGIN_METHOD(RegExp_Replace, GB_STRING subject; GB_STRING pattern; GB_STRING rep exec(&r, GB.StringLength(subject) - offset); if (r.ovector[0] < 0) - { - result = GB.AddString(result, &subject[offset], GB.StringLength(subject) - offset); - //fprintf(stderr, "result = %s\n", result); break; - } _subst_regexp = &r; if (r.ovector[0] > 0) { #if DEBUG_REPLACE - fprintf(stderr, "add: (%d) %.*s\n", lp, r.ovector[i * 2] - lp, &r.subject[lp]); + fprintf(stderr, "add: (%d) %.*s\n", r.ovector[0], r.ovector[0], r.subject); #endif result = GB.AddString(result, r.subject, r.ovector[0]); #if DEBUG_REPLACE @@ -422,8 +418,14 @@ BEGIN_METHOD(RegExp_Replace, GB_STRING subject; GB_STRING pattern; GB_STRING rep #endif offset += r.ovector[1]; + + if (*r.pattern == '^') + break; } + if (offset < LENGTH(subject)) + result = GB.AddString(result, &subject[offset], LENGTH(subject) - offset); + _subst_regexp = NULL; GB.FreeStringLater(result);