Blob
1 .TH REGEXP9 32 .de EX3 .nf4 .ft B5 ..6 .de EE7 .fi8 .ft R9 ..10 .de LR11 .if t .BR \\$1 \\$212 .if n .RB ` \\$1 '\\$213 ..14 .de L15 .nh16 .if t .B \\$117 .if n .RB ` \\$1 '18 ..19 .SH NAME20 regcomp, regcomplit, regcompnl, regexec, regsub, regerror \- Plan 9 regular expression library21 .SH SYNOPSIS22 .B #include <regexp9.h>23 .PP24 .ta \w'\fLRegprog 'u25 .B26 Reprog *regcomp(char *exp)27 .PP28 .B29 Reprog *regcomplit(char *exp)30 .PP31 .B32 Reprog *regcompnl(char *exp)33 .PP34 .nf35 .B36 int regexec(Reprog *prog, char *string, Resub *match, int msize)37 .PP38 .nf39 .B40 void regsub(char *source, char *dest, int dlen, Resub *match, int msize)41 .PP42 .nf43 .B44 int rregexec(Reprog *prog, Rune *string, Resub *match, int msize)45 .PP46 .nf47 .B48 void rregsub(Rune *source, Rune *dest, int dlen, Resub *match, int msize)49 .PP50 .B51 void regerror(char *msg)52 .SH DESCRIPTION53 .I Regcomp54 compiles a55 regular expression and returns56 a pointer to the generated description.57 The space is allocated by58 .IR malloc (3)59 and may be released by60 .IR free .61 Regular expressions are exactly as in62 .IR regexp9 (7).63 .PP64 .I Regcomplit65 is like66 .I regcomp67 except that all characters are treated literally.68 .I Regcompnl69 is like70 .I regcomp71 except that the72 .B .73 metacharacter matches all characters, including newlines.74 .PP75 .I Regexec76 matches a null-terminated77 .I string78 against the compiled regular expression in79 .IR prog .80 If it matches,81 .I regexec82 returns83 .B 184 and fills in the array85 .I match86 with character pointers to the substrings of87 .I string88 that correspond to the89 parenthesized subexpressions of90 .IR exp :91 .BI match[ i ].sp92 points to the beginning and93 .BI match[ i ].ep94 points just beyond95 the end of the96 .IR i th97 substring.98 (Subexpression99 .I i100 begins at the101 .IR i th102 left parenthesis, counting from 1.)103 Pointers in104 .B match[0]105 pick out the substring that corresponds to106 the whole regular expression.107 Unused elements of108 .I match109 are filled with zeros.110 Matches involving111 .LR * ,112 .LR + ,113 and114 .L ?115 are extended as far as possible.116 The number of array elements in117 .I match118 is given by119 .IR msize .120 The structure of elements of121 .I match122 is:123 .IP124 .EX125 typedef struct {126 union {127 char *sp;128 Rune *rsp;129 } s;130 union {131 char *ep;132 Rune *rep;133 } e;134 } Resub;135 .EE136 .LP137 If138 .B match[0].s.sp139 is nonzero on entry,140 .I regexec141 starts matching at that point within142 .IR string .143 If144 .B match[0].e.ep145 is nonzero on entry,146 the last character matched is the one147 preceding that point.148 .PP149 .I Regsub150 places in151 .I dest152 a substitution instance of153 .I source154 in the context of the last155 .I regexec156 performed using157 .IR match .158 Each instance of159 .BI \e n\f1,160 where161 .I n162 is a digit, is replaced by the163 string delimited by164 .BI match[ n ].s.sp165 and166 .BI match[ n ].e.ep\f1.167 Each instance of168 .L &169 is replaced by the string delimited by170 .B match[0].s.sp171 and172 .BR match[0].e.ep .173 The substitution will always be null terminated and174 trimmed to fit into dlen bytes.175 .PP176 .IR Regerror ,177 called whenever an error is detected in178 .IR regcomp ,179 writes the string180 .I msg181 on the standard error file and exits.182 .I Regerror183 can be replaced to perform184 special error processing.185 If the user supplied186 .I regerror187 returns rather than exits,188 .I regcomp189 will return 0.190 .PP191 .I Rregexec192 and193 .I rregsub194 are variants of195 .I regexec196 and197 .I regsub198 that use strings of199 .B Runes200 instead of strings of201 .BR chars .202 With these routines, the203 .I rsp204 and205 .I rep206 fields of the207 .I match208 array elements should be used.209 .SH "SEE ALSO"210 .IR grep (1),211 .IR regexp9 (7)212 .SH DIAGNOSTICS213 .I Regcomp214 returns215 .B 0216 for an illegal expression217 or other failure.218 .I Regexec219 returns 0220 if221 .I string222 is not matched.223 .SH HISTORY224 This particular regular expression was first written by Rob Pike for Plan 9.225 It has also appeared as part of the Inferno operating system.226 .SH BUGS227 There is no way to specify or match a NUL character; NULs terminate patterns and strings.