1 b2cfc4e2 2003-09-30 devnull .TH REGEXP9 3
11 b2cfc4e2 2003-09-30 devnull .if t .BR \\$1 \\$2
12 b2cfc4e2 2003-09-30 devnull .if n .RB ` \\$1 '\\$2
16 b2cfc4e2 2003-09-30 devnull .if t .B \\$1
17 b2cfc4e2 2003-09-30 devnull .if n .RB ` \\$1 '
20 b2cfc4e2 2003-09-30 devnull regcomp, regcomplit, regcompnl, regexec, regsub, regerror \- Plan 9 regular expression library
21 b2cfc4e2 2003-09-30 devnull .SH SYNOPSIS
22 b2cfc4e2 2003-09-30 devnull .B #include <regexp9.h>
24 b2cfc4e2 2003-09-30 devnull .ta \w'\fLRegprog 'u
26 b2cfc4e2 2003-09-30 devnull Reprog *regcomp(char *exp)
29 b2cfc4e2 2003-09-30 devnull Reprog *regcomplit(char *exp)
32 b2cfc4e2 2003-09-30 devnull Reprog *regcompnl(char *exp)
36 b2cfc4e2 2003-09-30 devnull int regexec(Reprog *prog, char *string, Resub *match, int msize)
40 b2cfc4e2 2003-09-30 devnull void regsub(char *source, char *dest, int dlen, Resub *match, int msize)
44 b2cfc4e2 2003-09-30 devnull int rregexec(Reprog *prog, Rune *string, Resub *match, int msize)
48 b2cfc4e2 2003-09-30 devnull void rregsub(Rune *source, Rune *dest, int dlen, Resub *match, int msize)
51 b2cfc4e2 2003-09-30 devnull void regerror(char *msg)
52 b2cfc4e2 2003-09-30 devnull .SH DESCRIPTION
53 b2cfc4e2 2003-09-30 devnull .I Regcomp
54 b2cfc4e2 2003-09-30 devnull compiles a
55 b2cfc4e2 2003-09-30 devnull regular expression and returns
56 b2cfc4e2 2003-09-30 devnull a pointer to the generated description.
57 b2cfc4e2 2003-09-30 devnull The space is allocated by
58 b2cfc4e2 2003-09-30 devnull .IR malloc (3)
59 b2cfc4e2 2003-09-30 devnull and may be released by
60 b2cfc4e2 2003-09-30 devnull .IR free .
61 b2cfc4e2 2003-09-30 devnull Regular expressions are exactly as in
62 b2cfc4e2 2003-09-30 devnull .IR regexp9 (7).
64 b2cfc4e2 2003-09-30 devnull .I Regcomplit
66 b2cfc4e2 2003-09-30 devnull .I regcomp
67 b2cfc4e2 2003-09-30 devnull except that all characters are treated literally.
68 b2cfc4e2 2003-09-30 devnull .I Regcompnl
70 b2cfc4e2 2003-09-30 devnull .I regcomp
71 b2cfc4e2 2003-09-30 devnull except that the
73 b2cfc4e2 2003-09-30 devnull metacharacter matches all characters, including newlines.
75 b2cfc4e2 2003-09-30 devnull .I Regexec
76 b2cfc4e2 2003-09-30 devnull matches a null-terminated
77 b2cfc4e2 2003-09-30 devnull .I string
78 b2cfc4e2 2003-09-30 devnull against the compiled regular expression in
79 b2cfc4e2 2003-09-30 devnull .IR prog .
80 b2cfc4e2 2003-09-30 devnull If it matches,
81 b2cfc4e2 2003-09-30 devnull .I regexec
84 b2cfc4e2 2003-09-30 devnull and fills in the array
86 b2cfc4e2 2003-09-30 devnull with character pointers to the substrings of
87 b2cfc4e2 2003-09-30 devnull .I string
88 b2cfc4e2 2003-09-30 devnull that correspond to the
89 b2cfc4e2 2003-09-30 devnull parenthesized subexpressions of
90 b2cfc4e2 2003-09-30 devnull .IR exp :
91 b2cfc4e2 2003-09-30 devnull .BI match[ i ].sp
92 b2cfc4e2 2003-09-30 devnull points to the beginning and
93 b2cfc4e2 2003-09-30 devnull .BI match[ i ].ep
94 b2cfc4e2 2003-09-30 devnull points just beyond
95 b2cfc4e2 2003-09-30 devnull the end of the
97 b2cfc4e2 2003-09-30 devnull substring.
98 b2cfc4e2 2003-09-30 devnull (Subexpression
100 b2cfc4e2 2003-09-30 devnull begins at the
101 b2cfc4e2 2003-09-30 devnull .IR i th
102 b2cfc4e2 2003-09-30 devnull left parenthesis, counting from 1.)
103 b2cfc4e2 2003-09-30 devnull Pointers in
104 b2cfc4e2 2003-09-30 devnull .B match[0]
105 b2cfc4e2 2003-09-30 devnull pick out the substring that corresponds to
106 b2cfc4e2 2003-09-30 devnull the whole regular expression.
107 b2cfc4e2 2003-09-30 devnull Unused elements of
108 b2cfc4e2 2003-09-30 devnull .I match
109 b2cfc4e2 2003-09-30 devnull are filled with zeros.
110 b2cfc4e2 2003-09-30 devnull Matches involving
115 b2cfc4e2 2003-09-30 devnull are extended as far as possible.
116 b2cfc4e2 2003-09-30 devnull The number of array elements in
117 b2cfc4e2 2003-09-30 devnull .I match
118 b2cfc4e2 2003-09-30 devnull is given by
119 b2cfc4e2 2003-09-30 devnull .IR msize .
120 b2cfc4e2 2003-09-30 devnull The structure of elements of
121 b2cfc4e2 2003-09-30 devnull .I match
125 b2cfc4e2 2003-09-30 devnull typedef struct {
127 b2cfc4e2 2003-09-30 devnull char *sp;
128 b2cfc4e2 2003-09-30 devnull Rune *rsp;
131 b2cfc4e2 2003-09-30 devnull char *ep;
132 b2cfc4e2 2003-09-30 devnull Rune *rep;
134 b2cfc4e2 2003-09-30 devnull } Resub;
138 b2cfc4e2 2003-09-30 devnull .B match[0].s.sp
139 b2cfc4e2 2003-09-30 devnull is nonzero on entry,
140 b2cfc4e2 2003-09-30 devnull .I regexec
141 b2cfc4e2 2003-09-30 devnull starts matching at that point within
142 b2cfc4e2 2003-09-30 devnull .IR string .
144 b2cfc4e2 2003-09-30 devnull .B match[0].e.ep
145 b2cfc4e2 2003-09-30 devnull is nonzero on entry,
146 b2cfc4e2 2003-09-30 devnull the last character matched is the one
147 b2cfc4e2 2003-09-30 devnull preceding that point.
149 b2cfc4e2 2003-09-30 devnull .I Regsub
150 b2cfc4e2 2003-09-30 devnull places in
152 b2cfc4e2 2003-09-30 devnull a substitution instance of
153 b2cfc4e2 2003-09-30 devnull .I source
154 b2cfc4e2 2003-09-30 devnull in the context of the last
155 b2cfc4e2 2003-09-30 devnull .I regexec
156 b2cfc4e2 2003-09-30 devnull performed using
157 b2cfc4e2 2003-09-30 devnull .IR match .
158 b2cfc4e2 2003-09-30 devnull Each instance of
159 b2cfc4e2 2003-09-30 devnull .BI \e n\f1,
162 b2cfc4e2 2003-09-30 devnull is a digit, is replaced by the
163 b2cfc4e2 2003-09-30 devnull string delimited by
164 b2cfc4e2 2003-09-30 devnull .BI match[ n ].s.sp
166 b2cfc4e2 2003-09-30 devnull .BI match[ n ].e.ep\f1.
167 b2cfc4e2 2003-09-30 devnull Each instance of
169 b2cfc4e2 2003-09-30 devnull is replaced by the string delimited by
170 b2cfc4e2 2003-09-30 devnull .B match[0].s.sp
172 b2cfc4e2 2003-09-30 devnull .BR match[0].e.ep .
173 b2cfc4e2 2003-09-30 devnull The substitution will always be null terminated and
174 b2cfc4e2 2003-09-30 devnull trimmed to fit into dlen bytes.
176 b2cfc4e2 2003-09-30 devnull .IR Regerror ,
177 b2cfc4e2 2003-09-30 devnull called whenever an error is detected in
178 b2cfc4e2 2003-09-30 devnull .IR regcomp ,
179 b2cfc4e2 2003-09-30 devnull writes the string
181 b2cfc4e2 2003-09-30 devnull on the standard error file and exits.
182 b2cfc4e2 2003-09-30 devnull .I Regerror
183 b2cfc4e2 2003-09-30 devnull can be replaced to perform
184 b2cfc4e2 2003-09-30 devnull special error processing.
185 b2cfc4e2 2003-09-30 devnull If the user supplied
186 b2cfc4e2 2003-09-30 devnull .I regerror
187 b2cfc4e2 2003-09-30 devnull returns rather than exits,
188 b2cfc4e2 2003-09-30 devnull .I regcomp
189 b2cfc4e2 2003-09-30 devnull will return 0.
191 b2cfc4e2 2003-09-30 devnull .I Rregexec
193 b2cfc4e2 2003-09-30 devnull .I rregsub
194 b2cfc4e2 2003-09-30 devnull are variants of
195 b2cfc4e2 2003-09-30 devnull .I regexec
197 b2cfc4e2 2003-09-30 devnull .I regsub
198 b2cfc4e2 2003-09-30 devnull that use strings of
199 b2cfc4e2 2003-09-30 devnull .B Runes
200 b2cfc4e2 2003-09-30 devnull instead of strings of
201 b2cfc4e2 2003-09-30 devnull .BR chars .
202 b2cfc4e2 2003-09-30 devnull With these routines, the
206 b2cfc4e2 2003-09-30 devnull fields of the
207 b2cfc4e2 2003-09-30 devnull .I match
208 b2cfc4e2 2003-09-30 devnull array elements should be used.
209 b2cfc4e2 2003-09-30 devnull .SH "SEE ALSO"
210 b2cfc4e2 2003-09-30 devnull .IR grep (1),
211 b2cfc4e2 2003-09-30 devnull .IR regexp9 (7)
212 b2cfc4e2 2003-09-30 devnull .SH DIAGNOSTICS
213 b2cfc4e2 2003-09-30 devnull .I Regcomp
216 b2cfc4e2 2003-09-30 devnull for an illegal expression
217 b2cfc4e2 2003-09-30 devnull or other failure.
218 b2cfc4e2 2003-09-30 devnull .I Regexec
219 b2cfc4e2 2003-09-30 devnull returns 0
221 b2cfc4e2 2003-09-30 devnull .I string
222 b2cfc4e2 2003-09-30 devnull is not matched.
223 b2cfc4e2 2003-09-30 devnull .SH HISTORY
224 b2cfc4e2 2003-09-30 devnull This particular regular expression was first written by Rob Pike for Plan 9.
225 b2cfc4e2 2003-09-30 devnull It has also appeared as part of the Inferno operating system.
226 b2cfc4e2 2003-09-30 devnull .SH BUGS
227 b2cfc4e2 2003-09-30 devnull There is no way to specify or match a NUL character; NULs terminate patterns and strings.