aboutsummaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorJ.T. Conklin <jtc@FreeBSD.org>1993-10-04 21:58:53 +0000
committerJ.T. Conklin <jtc@FreeBSD.org>1993-10-04 21:58:53 +0000
commit4a13ab7c12be6a84cfbb88bf6fe64ae3ca79f08e (patch)
tree86826d0ba464f1e9bfbc74eebc783dfd3b18ae77 /bin
parent20c7f6036713e34d81cf4001135feeafd9c0bd64 (diff)
downloadsrc-4a13ab7c12be6a84cfbb88bf6fe64ae3ca79f08e.tar.gz
src-4a13ab7c12be6a84cfbb88bf6fe64ae3ca79f08e.zip
Allow expressions like "expr 'ABC' : '^.*$' to work as is done in other
expr implementations.
Notes
Notes: svn path=/head/; revision=539
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 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);