mjr@osiris.UUCP (Marcus J. Ranum) (08/25/87)
I've been playing with the BSD regexp libary routines. I had the same experience with regexp.h, too. Anyhow: expressions like: "aplcen!mj*" and even "aplcen!mj." compile fine using re_comp() and when I try a re_exec() against a string like "aplcen!mjr" they DON'T MATCH if I've already compiled one or more re's. Now, the ed(1) manpage tells me I should get at least something out of that. About the only thing that DID re_exec() okay against my compiled string was "mjr" which DID match. Anyone seen this before ?? I tried the following: extern char *re_comp(); main() { char *fp = "aplcen!mjr"; char *bp = "aplcen!*"; char *qp = "*!*"; char *ap; if(ap = re_comp(bp)) { printf("err - %s\n",ap); exit(1); } else { if(re_exec(fp)) printf("match one!\n"); } if(ap = re_comp(qp)) { printf("err - %s\n",ap); exit(1); } else { if(re_exec(fp)) printf("match two!\n"); } exit(0); } -- If they think you're crude, go technical; if they think you're technical, go crude. I'm a very technical boy. So I get as crude as possible. These days, though, you have to be pretty technical before you can even aspire to crudeness... -Johnny Mnemonic
chris@mimsy.UUCP (Chris Torek) (08/25/87)
In article <1358@osiris.UUCP> mjr@osiris.UUCP (Marcus J. Ranum) writes: >expressions like: "aplcen!mj*" and even "aplcen!mj." compile fine using >re_comp() and when I try a re_exec() against a string like "aplcen!mjr" >they DON'T MATCH if I've already compiled one or more re's. ... > >I tried the following: [paraphrased] char *fp = "aplcen!mjr", *ap; if (ap = re_comp("aplcen!*")) { printf("err - %s\n",ap); exit(1); } if (re_exec(fp)) printf("match one!\n"); if (ap = re_comp("*!*)) { printf("err - %s\n",ap); exit(1); } if (re_exec(fp)) printf("match two!\n"); Remember, re_comp compiles an *ed*-style regular expression, not a shell-style file match expression. Try compiling `aplcen!.*' and `.*!.*' instead. -- In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7690) Domain: chris@mimsy.umd.edu Path: seismo!mimsy!chris
nate@altos86.UUCP (Nathaniel Ingersoll) (08/27/87)
The * is in Ex and friends is different from that in Csh. xxxx* in csh will match any pattern starting with four x's, while in Ex it will match a string of at least 3 x's - xxx and then (x*) == zero or more x's. So for re_comp you need xxxx.* which is 4 x's, and zero or more .'s and . being a wild match which will match any single character.