Blob
1 .TH REGEXP9 32 .SH NAME3 regcomp, regcomplit, regcompnl, regexec, regsub, rregexec, rregsub, regerror \- regular expression4 .SH SYNOPSIS5 .B #include <utf.h>6 .br7 .B #include <fmt.h>8 .br9 .B #include <regexp9.h>10 .PP11 .ta \w'\fLRegprog 'u12 .B13 Reprog *regcomp(char *exp)14 .PP15 .B16 Reprog *regcomplit(char *exp)17 .PP18 .B19 Reprog *regcompnl(char *exp)20 .PP21 .nf22 .B23 int regexec(Reprog *prog, char *string, Resub *match, int msize)24 .PP25 .nf26 .B27 void regsub(char *source, char *dest, int dlen, Resub *match, int msize)28 .PP29 .nf30 .B31 int rregexec(Reprog *prog, Rune *string, Resub *match, int msize)32 .PP33 .nf34 .B35 void rregsub(Rune *source, Rune *dest, int dlen, Resub *match, int msize)36 .PP37 .B38 void regerror(char *msg)39 .SH DESCRIPTION40 .I Regcomp41 compiles a42 regular expression and returns43 a pointer to the generated description.44 The space is allocated by45 .IR malloc (3)46 and may be released by47 .IR free .48 Regular expressions are exactly as in49 .IR regexp9 (7).50 .PP51 .I Regcomplit52 is like53 .I regcomp54 except that all characters are treated literally.55 .I Regcompnl56 is like57 .I regcomp58 except that the59 .B .60 metacharacter matches all characters, including newlines.61 .PP62 .I Regexec63 matches a null-terminated64 .I string65 against the compiled regular expression in66 .IR prog .67 If it matches,68 .I regexec69 returns70 .B 171 and fills in the array72 .I match73 with character pointers to the substrings of74 .I string75 that correspond to the76 parenthesized subexpressions of77 .IR exp :78 .BI match[ i ].sp79 points to the beginning and80 .BI match[ i ].ep81 points just beyond82 the end of the83 .IR i th84 substring.85 (Subexpression86 .I i87 begins at the88 .IR i th89 left parenthesis, counting from 1.)90 Pointers in91 .B match[0]92 pick out the substring that corresponds to93 the whole regular expression.94 Unused elements of95 .I match96 are filled with zeros.97 Matches involving98 .LR * ,99 .LR + ,100 and101 .L ?102 are extended as far as possible.103 The number of array elements in104 .I match105 is given by106 .IR msize .107 The structure of elements of108 .I match109 is:110 .IP111 .EX112 typedef struct {113 union {114 char *sp;115 Rune *rsp;116 };117 union {118 char *ep;119 Rune *rep;120 };121 } Resub;122 .EE123 .LP124 If125 .B match[0].sp126 is nonzero on entry,127 .I regexec128 starts matching at that point within129 .IR string .130 If131 .B match[0].ep132 is nonzero on entry,133 the last character matched is the one134 preceding that point.135 .PP136 .I Regsub137 places in138 .I dest139 a substitution instance of140 .I source141 in the context of the last142 .I regexec143 performed using144 .IR match .145 Each instance of146 .BI \e n\f1,147 where148 .I n149 is a digit, is replaced by the150 string delimited by151 .BI match[ n ].sp152 and153 .BI match[ n ].ep\f1.154 Each instance of155 .L &156 is replaced by the string delimited by157 .B match[0].sp158 and159 .BR match[0].ep .160 The substitution will always be null terminated and161 trimmed to fit into dlen bytes.162 .PP163 .IR Regerror ,164 called whenever an error is detected in165 .IR regcomp ,166 writes the string167 .I msg168 on the standard error file and exits.169 .I Regerror170 can be replaced to perform171 special error processing.172 If the user supplied173 .I regerror174 returns rather than exits,175 .I regcomp176 will return 0.177 .PP178 .I Rregexec179 and180 .I rregsub181 are variants of182 .I regexec183 and184 .I regsub185 that use strings of186 .B Runes187 instead of strings of188 .BR chars .189 With these routines, the190 .I rsp191 and192 .I rep193 fields of the194 .I match195 array elements should be used.196 .SH SOURCE197 .B http://swtch.com/plan9port/unix198 .SH "SEE ALSO"199 .IR grep (1)200 .SH DIAGNOSTICS201 .I Regcomp202 returns203 .B 0204 for an illegal expression205 or other failure.206 .I Regexec207 returns 0208 if209 .I string210 is not matched.211 .SH BUGS212 There is no way to specify or match a NUL character; NULs terminate patterns and strings.