--- util.c.orig 2016-07-12 20:38:58.493538000 +0200 +++ util.c 2016-07-12 20:42:49.871234000 +0200 @@ -281,14 +281,19 @@ pmatch.rm_so = st; pmatch.rm_eo = l->len; + /* Position-adjusted eflags, if we are beyond the first + character, we have to set REG_NOTBOL to ensure that + anchors are handled correctly. */ + int peflags = eflags | (st == 0 ? 0 : REG_NOTBOL); + /* Loop to compare with all the patterns */ for (i = 0; i < patterns; i++) { if (fg_pattern[i].pattern) r = fastexec(&fg_pattern[i], - l->dat, 1, &pmatch, eflags); + l->dat, 1, &pmatch, peflags); else r = regexec(&r_pattern[i], l->dat, 1, - &pmatch, eflags); + &pmatch, peflags); r = (r == 0) ? 0 : REG_NOMATCH; st = (cflags & REG_NOSUB) ? (size_t)l->len