aboutsummaryrefslogtreecommitdiff
path: root/man/man3/regexp.html
blob: 21e1849b06170cb87b294eae2174ccbb261d7b23 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
<head>
<title>regexp(3) - Plan 9 from User Space</title>
<meta content="text/html; charset=utf-8" http-equiv=Content-Type>
</head>
<body bgcolor=#ffffff>
<table border=0 cellpadding=0 cellspacing=0 width=100%>
<tr height=10><td>
<tr><td width=20><td>
<tr><td width=20><td><b>REGEXP(3)</b><td align=right><b>REGEXP(3)</b>
<tr><td width=20><td colspan=2>
    <br>
<p><font size=+1><b>NAME     </b></font><br>

<table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>

    regcomp, regcomplit, regcompnl, regexec, regsub, rregexec, rregsub,
    regerror &ndash; regular expression<br>
    
</table>
<p><font size=+1><b>SYNOPSIS     </b></font><br>

<table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>

    <tt><font size=+1>#include &lt;u.h&gt;<br>
    #include &lt;libc.h&gt;<br>
    #include &lt;regexp.h&gt; 
    <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
    </font></tt>
    <tt><font size=+1>Reprog &nbsp;&nbsp;&nbsp;*regcomp(char *exp) 
    <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
    </font></tt>
    <tt><font size=+1>Reprog &nbsp;&nbsp;&nbsp;*regcomplit(char *exp) 
    <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
    </font></tt>
    <tt><font size=+1>Reprog &nbsp;&nbsp;&nbsp;*regcompnl(char *exp) 
    <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
    </font></tt>
    <tt><font size=+1>int &nbsp;&nbsp;&nbsp;regexec(Reprog *prog, char *string, Resub *match, int msize)<br>
    
    <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
    </font></tt>
    <tt><font size=+1>void regsub(char *source, char *dest, int dlen, Resub *match,
    int msize)<br>
    
    <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
    </font></tt>
    <tt><font size=+1>int &nbsp;&nbsp;&nbsp;rregexec(Reprog *prog, Rune *string, Resub *match, int msize)<br>
    
    <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
    </font></tt>
    <tt><font size=+1>void rregsub(Rune *source, Rune *dest, int dlen, Resub *match,
    int msize)<br>
    
    <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
    </font></tt>
    <tt><font size=+1>void regerror(char *msg)<br>
    </font></tt>
</table>
<p><font size=+1><b>DESCRIPTION     </b></font><br>

<table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>

    <i>Regcomp</i> compiles a regular expression and returns a pointer to
    the generated description. The space is allocated by <a href="../man3/malloc.html"><i>malloc</i>(3)</a>
    and may be released by <i>free</i>. Regular expressions are exactly as
    in <a href="../man7/regexp.html"><i>regexp</i>(7)</a>. 
    <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
    
    <i>Regcomplit</i> is like <i>regcomp</i> except that all characters are treated
    literally. <i>Regcompnl</i> is like <i>regcomp</i> except that the <tt><font size=+1>.</font></tt> metacharacter
    matches all characters, including newlines. 
    <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
    
    <i>Regexec</i> matches a null-terminated <i>string</i> against the compiled
    regular expression in <i>prog</i>. If it matches, <i>regexec</i> returns <tt><font size=+1>1</font></tt> and
    fills in the array <i>match</i> with character pointers to the substrings
    of <i>string</i> that correspond to the parenthesized subexpressions
    of <i>exp</i>: <tt><font size=+1>match[</font></tt><i>i</i><tt><font size=+1>].sp</font></tt> points to the beginning and
    <tt><font size=+1>match[</font></tt><i>i</i><tt><font size=+1>].ep</font></tt> points just beyond the end of the <i>i</i>th substring. (Subexpression
    <i>i</i> begins at the <i>i</i>th left parenthesis, counting from 1.) Pointers
    in <tt><font size=+1>match[0]</font></tt> pick out the substring that corresponds to the whole
    regular expression. Unused elements of <i>match</i> are filled with zeros.
    Matches involving <tt><font size=+1>*</font></tt>, <tt><font size=+1>+</font></tt>, and <tt><font size=+1>?</font></tt> are
    extended as far as possible. The number of array elements in <i>match</i>
    is given by <i>msize</i>. The structure of elements of <i>match</i> is:<br>
    
    <table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>

        <tt><font size=+1>typedef struct {<br>
        
        <table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>

            union {<br>
             char *sp;<br>
             Rune *rsp;<br>
            } s;<br>
            union {<br>
             char *ep;<br>
             Rune *rep;<br>
            } e;<br>
            
        </table>
        } Resub;<br>
        
        <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
        </font></tt>
        
    </table>
    If <tt><font size=+1>match[0].s.sp</font></tt> is nonzero on entry, <i>regexec</i> starts matching
    at that point within <i>string</i>. If <tt><font size=+1>match[0].e.ep</font></tt> is nonzero on entry,
    the last character matched is the one preceding that point. 
    <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
    
    <i>Regsub</i> places in <i>dest</i> a substitution instance of <i>source</i> in the
    context of the last <i>regexec</i> performed using <i>match</i>. Each instance
    of <tt><font size=+1>\</font></tt><i>n</i>, where <i>n</i> is a digit, is replaced by the string delimited
    by <tt><font size=+1>match[</font></tt><i>n</i><tt><font size=+1>].sp</font></tt> and <tt><font size=+1>match[</font></tt><i>n</i><tt><font size=+1>].ep</font></tt>. Each instance of <tt><font size=+1>&amp;</font></tt> is replaced
    by the string delimited by <tt><font size=+1>match[0].sp</font></tt> and
    <tt><font size=+1>match[0].ep</font></tt>. The substitution will always be null terminated and
    trimmed to fit into dlen bytes. 
    <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
    
    <i>Regerror</i>, called whenever an error is detected in <i>regcomp</i>, writes
    the string <i>msg</i> on the standard error file and exits. <i>Regerror</i>
    can be replaced to perform special error processing. If the user
    supplied <i>regerror</i> returns rather than exits, <i>regcomp</i> will return
    0. 
    <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
    
    <i>Rregexec</i> and <i>rregsub</i> are variants of <i>regexec</i> and <i>regsub</i> that use
    strings of <tt><font size=+1>Runes</font></tt> instead of strings of <tt><font size=+1>chars</font></tt>. With these routines,
    the <i>rsp</i> and <i>rep</i> fields of the <i>match</i> array elements should be used.<br>
    
</table>
<p><font size=+1><b>SOURCE     </b></font><br>

<table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>

    <tt><font size=+1>/usr/local/plan9/src/libregexp<br>
    </font></tt>
</table>
<p><font size=+1><b>SEE ALSO     </b></font><br>

<table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>

    <a href="../man1/grep.html"><i>grep</i>(1)</a><br>
    
</table>
<p><font size=+1><b>DIAGNOSTICS     </b></font><br>

<table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>

    <i>Regcomp</i> returns <tt><font size=+1>0</font></tt> for an illegal expression or other failure.
    <i>Regexec</i> returns 0 if <i>string</i> is not matched.<br>
    
</table>
<p><font size=+1><b>BUGS     </b></font><br>

<table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>

    There is no way to specify or match a NUL character; NULs terminate
    patterns and strings.<br>
    
</table>

<td width=20>
<tr height=20><td>
</table>
<!-- TRAILER -->
<table border=0 cellpadding=0 cellspacing=0 width=100%>
<tr height=15><td width=10><td><td width=10>
<tr><td><td>
<center>
<a href="../../"><img src="../../dist/spaceglenda100.png" alt="Space Glenda" border=1></a>
</center>
</table>
<!-- TRAILER -->
</body></html>