From a942eef12415e0b53e04279259dd92cca4d444f0 Mon Sep 17 00:00:00 2001 From: Steve Bennett Date: Mon, 4 May 2020 15:02:19 +1000 Subject: regsub: Fix regsub -all with \A regsub -all matches \A against the start of each match, but correctly handle a pattern like ^ which does not advance the match Signed-off-by: Steve Bennett --- jim-regexp.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'jim-regexp.c') diff --git a/jim-regexp.c b/jim-regexp.c index b0411f8..880bf33 100644 --- a/jim-regexp.c +++ b/jim-regexp.c @@ -540,7 +540,14 @@ int Jim_RegsubCmd(Jim_Interp *interp, int argc, Jim_Obj *const *argv) n--; } - regexec_flags |= REG_NOTBOL; + if (pmatch[0].rm_eo == pmatch[0].rm_so) { + /* The match did not advance the string, so set REG_NOTBOL to force the next match */ + regexec_flags = REG_NOTBOL; + } + else { + regexec_flags = 0; + } + } while (n); /* -- cgit v1.1