xref: /original-bsd/lib/libcompat/4.3/re_comp.3 (revision 1ff91bf0)
1.\" Copyright (c) 1980, 1991 Regents of the University of California.
2.\" All rights reserved.
3.\"
4.\" %sccs.include.redist.man%
5.\"
6.\"     @(#)re_comp.3	6.3 (Berkeley) 04/19/91
7.\"
8.Dd
9.Dt REGEX 3
10.Os
11.Sh NAME
12.Nm re_comp ,
13.Nm re_exec
14.Nd regular expression handler
15.Sh SYNOPSIS
16.Fd #include <unistd.h>
17.Ft char *
18.Fn re_comp "const char *s"
19.Ft int
20.Fn re_exec "const char *s"
21.Sh DESCRIPTION
22The
23.Fn re_comp
24function
25compiles a string into an internal form suitable for pattern matching.
26The
27.Fn re_exec
28function
29checks the argument string against the last string passed to
30.Fn re_comp .
31.Pp
32The
33.Fn re_comp
34function
35returns 0 if the string
36.Fa s
37was compiled successfully; otherwise a string containing an
38error message is returned. If
39.Fn re_comp
40is passed 0 or a null string, it returns without changing the currently
41compiled regular expression.
42.Pp
43The
44.Fn re_exec
45function
46returns 1 if the string
47.Fa s
48matches the last compiled regular expression, 0 if the string
49.Fa s
50failed to match the last compiled regular expression, and \-1 if the compiled
51regular expression was invalid (indicating an internal error).
52.Pp
53The strings passed to both
54.Fn re_comp
55and
56.Fn re_exec
57may have trailing or embedded newline characters;
58they are terminated by
59.Dv NUL Ns s.
60The regular expressions recognized are described in the manual entry for
61.Xr ed 1 ,
62given the above difference.
63.Sh DIAGNOSTICS
64The
65.Fn re_exec
66function
67returns \-1 for an internal error.
68.Pp
69The
70.Fn re_comp
71function
72returns one of the following strings if an error occurs:
73.Bd -unfilled -offset indent
74No previous regular expression,
75Regular expression too long,
76unmatched \e(,
77missing ],
78too many \e(\e) pairs,
79unmatched \e).
80.Ed
81.Sh SEE ALSO
82.Xr ed 1 ,
83.Xr ex 1 ,
84.Xr egrep 1 ,
85.Xr fgrep 1 ,
86.Xr grep 1 ,
87.Xr regexp 3
88.Sh HISTORY
89The
90.Fn re_comp
91and
92.Fn re_exec
93functions appeared in
94.Bx 4.0 .
95