Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!lll-crg!caip!clyde!burl!ulysses!bellcore!whuxcc!lcuxlm!whuxl!houxm!ihnp4!cuae2!ltuxa!we53!sw013b!dj3b1!killer!ozdaltx!root From: root@ozdaltx.UUCP (root) Newsgroups: net.unix Subject: Re: regexp(3) - a request for a clear explanation Message-ID: <272@ozdaltx.UUCP> Date: Fri, 29-Aug-86 01:47:51 EDT Article-I.D.: ozdaltx.272 Posted: Fri Aug 29 01:47:51 1986 Date-Received: Sat, 30-Aug-86 10:01:46 EDT References: <516@chinet.UUCP> Distribution: net Lines: 57 Summary: regcmp([13]), regexp In article <516@chinet.UUCP>, megabyte@chinet.UUCP (Dr. Megabyte) writes: > I've poured myself over ny manual and looked at regcmp(1), regcmp(3), and > regexp(3), and I'm still not sure how to use these functions. Could someone I'll do the best I can. Hope this helps. My manuals are a little different in layout, (no section 1,2,3......) the command regcmp compiles a regular expression (shell style) into C source code with the output going to file.i or file.c. The format is in the form, VARIABLE "expression". The resulting file.[ic] may be included as part of a C program, (#include file.[ic]). Regexp(abc,line) applies the regular expression named abc to line. EXAMPLE: Variable Name (space) Expression teleno "\({0,1}([2-9][01][1-9])$0\){0,1} *" "([2-9][0-9]{2})$1[ -]{0,1}" "([0-9]{4})$2" Basicly this says: in field 0 (area code) accept optionally a ( followed by the digits of the specified ranges followed by a optional ). In field 1 (exchange) accept a number starting with 2 through 9 plus any other 2 numbers ranging 0-9, followed by an optional space or dash (-). Finially, field 2 will accept 4 numbers ranging 0-9. The above would be typed into a file, then regcmp run on the file. The resultant file should look like: /* "({0,1}([2-9][01][1-9])$0){0,1} *([2-9][0-9]{2})$1[ -]{0,1}([0-9]{4})$2" */ char teleno[] { 060,027,00,01,074,00,030,04,020,062,071,030, 03,060,061,030,04,020,061,071,014,00,00,057, 00,00,01,025,040,074,01,030,04,020,062,071, 033,04,020,060,071,02,02,014,01,01,033,03, 040,055,00,01,074,02,033,04,020,060,071,04, 04,014,02,02,064, 0}; In the C program that uses the regcmp output the following line will apply the expression named teleno to line: regex(teleno, line, area, exch, rest); The program regcmp is a lot easier to use than the function. Have fun! Scotty ...ihnp4!killer!ozdaltx!root "Oh, my friend, it's not what they take away from you that counts- It's what you do with what you have left." - Hubert Humphrey