regexp(3) - a request for a clear explanation
root
root at ozdaltx.UUCP
Fri Aug 29 15:47:51 AEST 1986
In article <516 at chinet.UUCP>, megabyte at 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
More information about the Comp.unix
mailing list