summaryrefslogtreecommitdiffstats
path: root/bin
diff options
context:
space:
mode:
authorjtc <jtc@FreeBSD.org>1993-10-04 21:58:53 +0000
committerjtc <jtc@FreeBSD.org>1993-10-04 21:58:53 +0000
commitc2f64d013cfa9338f88b4a516342e6d618a71376 (patch)
tree86826d0ba464f1e9bfbc74eebc783dfd3b18ae77 /bin
parente03159403ef933a60c01a89c78ebcdb388f66b36 (diff)
downloadFreeBSD-src-c2f64d013cfa9338f88b4a516342e6d618a71376.zip
FreeBSD-src-c2f64d013cfa9338f88b4a516342e6d618a71376.tar.gz
Allow expressions like "expr 'ABC' : '^.*$' to work as is done in other
expr implementations.
Diffstat (limited to 'bin')
-rw-r--r--bin/expr/expr.y12
1 files changed, 3 insertions, 9 deletions
diff --git a/bin/expr/expr.y b/bin/expr/expr.y
index e7a0a5a..57ad502 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);
OpenPOWER on IntegriCloud