summaryrefslogtreecommitdiff
path: root/src/lib/libast/man/strmatch.3
blob: 5f5af8989ecba8602ed77210effd3228267542b6 (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
.fp 5 CW
.de Af
.ds ;G \\*(;G\\f\\$1\\$3\\f\\$2
.if !\\$4 .Af \\$2 \\$1 "\\$4" "\\$5" "\\$6" "\\$7" "\\$8" "\\$9"
..
.de aF
.ie \\$3 .ft \\$1
.el \{\
.ds ;G \&
.nr ;G \\n(.f
.Af "\\$1" "\\$2" "\\$3" "\\$4" "\\$5" "\\$6" "\\$7" "\\$8" "\\$9"
\\*(;G
.ft \\n(;G \}
..
.de L
.aF 5 \\n(.f "\\$1" "\\$2" "\\$3" "\\$4" "\\$5" "\\$6" "\\$7"
..
.de LR
.aF 5 1 "\\$1" "\\$2" "\\$3" "\\$4" "\\$5" "\\$6" "\\$7"
..
.de RL
.aF 1 5 "\\$1" "\\$2" "\\$3" "\\$4" "\\$5" "\\$6" "\\$7"
..
.de EX		\" start example
.ta 1i 2i 3i 4i 5i 6i
.PP
.RS 
.PD 0
.ft 5
.nf
..
.de EE		\" end example
.fi
.ft
.PD
.RE
.PP
..
.TH STRMATCH 3
.SH NAME
strmatch \- match shell file patterns
.SH SYNOPSIS
.L "int strmatch(char* s, char* p)"
.br
.L "char* submatch(char* s, char* p, int m)"
.SH DESCRIPTION
.I strmatch
compares the string
.I s
with the shell pattern
.I p
and returns 1 for match and 0 otherwise.
.I submatch
does a leading substring match of the shell pattern
.I p
with the string
.IR s .
If
.I m
is 0 then the match is minimal, otherwise a maximal match is done.
A pointer to the first character after the matched substring is returned,
.I 0
if there is no match.
.PP
Except for
.I &
and
.IR ! ,
each shell pattern has an equivalent 
.IR egrep (1)
construct.
.EX
	\fBsh pattern	egrep RE	description\fP
	*		.*		0 or more chars
	?		.		any single char
	[.]		[.]		char class
	[!.]		[^.]		negated char class
	*(.)		(.)*		0 or more of
	+(.)		(.)+		1 or more of
	?(.)		(.)?		0 or 1 of
	(.)		(.)		1 of
	@(.)		(.)		1 of
	a|b		a|b		a or b
	a&b				a and b
	!(.)				none of
.EE
.L \e
is used to escape *, ?, (, |, &, ), [, and \e
outside of [...].
.SH "SEE ALSO"
grep(1)
.SH BUGS
An unbalanced
.L )
terminates the top level pattern.
.br
Nested
.L &
and
.L !
constructs are non-intuitive and are computationally intensive.