From d143e6f1752187377d29ea4d5187b09a1e875640 Mon Sep 17 00:00:00 2001 From: jtc Date: Mon, 4 Oct 1993 21:57:27 +0000 Subject: [PATCH] Allow expressions like "expr 'ABC' : '^.*$' to work as is done in other expr implementations. --- bin/expr/expr.y | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/bin/expr/expr.y b/bin/expr/expr.y index e7a0a5a7c47e..57ad5022e496 100644 --- a/bin/expr/expr.y +++ b/bin/expr/expr.y @@ -495,26 +495,20 @@ struct val *a, *b; char errbuf[256]; int eval; struct val *v; - char *newpat; /* coerce to both arguments to strings */ to_string(a); to_string(b); - /* patterns are anchored to the beginning of the line */ - newpat = malloc (strlen (b->u.s) + 2); - strcpy (newpat, "^"); - strcat (newpat, b->u.s); - /* compile regular expression */ - if ((eval = regcomp (&rp, newpat, 0)) != 0) { + if ((eval = regcomp (&rp, b->u.s, 0)) != 0) { regerror (eval, &rp, errbuf, sizeof(errbuf)); errx (2, "%s", errbuf); } - free (newpat); /* compare string against pattern */ - if (regexec(&rp, a->u.s, 2, rm, 0) == 0) { + /* remember that patterns are anchored to the beginning of the line */ + if (regexec(&rp, a->u.s, 2, rm, 0) == 0 && rm[0].rm_so == 0) { if (rm[1].rm_so >= 0) { *(a->u.s + rm[1].rm_eo) = '\0'; v = make_str (a->u.s + rm[1].rm_so);