Subversion Repositories planix.SVN

Rev

Rev 2 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 - 1
.TH REGEXP 6
2
.SH NAME
3
regexp \- regular expression notation
4
.SH DESCRIPTION
5
A 
6
.I "regular expression"
7
specifies
8
a set of strings of characters.
9
A member of this set of strings is said to be
10
.I matched
11
by the regular expression.  In many applications
12
a delimiter character, commonly
13
.LR / ,
14
bounds a regular expression.
15
In the following specification for regular expressions
16
the word `character' means any character (rune) but newline.
17
.PP
18
The syntax for a regular expression
19
.B e0
20
is
21
.IP
22
.EX
23
e3:  literal | charclass | '.' | '^' | '$' | '(' e0 ')'
24
 
25
e2:  e3
26
  |  e2 REP
27
 
28
REP: '*' | '+' | '?'
29
 
30
e1:  e2
31
  |  e1 e2
32
 
33
e0:  e1
34
  |  e0 '|' e1
35
.EE
36
.PP
37
A
38
.B literal
39
is any non-metacharacter, or a metacharacter
40
(one of
41
.BR .*+?[]()|\e^$ ),
42
or the delimiter
43
preceded by 
44
.LR \e .
45
.PP
46
A
47
.B charclass
48
is a nonempty string
49
.I s
50
bracketed
51
.BI [ \|s\| ]
52
(or
53
.BI [^ s\| ]\fR);
54
it matches any character in (or not in)
55
.IR s .
56
A negated character class never
57
matches newline.
58
A substring 
59
.IB a - b\f1,
60
with
61
.I a
62
and
63
.I b
64
in ascending
65
order, stands for the inclusive
66
range of
67
characters between
68
.I a
69
and
70
.IR b .
71
In 
72
.IR s ,
73
the metacharacters
74
.LR - ,
75
.LR ] ,
76
an initial
77
.LR ^ ,
78
and the regular expression delimiter
79
must be preceded by a
80
.LR \e ;
81
other metacharacters 
82
have no special meaning and
83
may appear unescaped.
84
.PP
85
A 
86
.L .
87
matches any character.
88
.PP
89
A
90
.L ^
91
matches the beginning of a line;
92
.L $
93
matches the end of the line.
94
.PP
95
The 
96
.B REP
97
operators match zero or more
98
.RB ( * ),
99
one or more
100
.RB ( + ),
101
zero or one
102
.RB ( ? ),
103
instances respectively of the preceding regular expression 
104
.BR e2 .
105
.PP
106
A concatenated regular expression,
107
.BR "e1\|e2" ,
108
matches a match to 
109
.B e1
110
followed by a match to
111
.BR e2 .
112
.PP
113
An alternative regular expression,
114
.BR "e0\||\|e1" ,
115
matches either a match to
116
.B e0
117
or a match to
118
.BR e1 .
119
.PP
120
A match to any part of a regular expression
121
extends as far as possible without preventing
122
a match to the remainder of the regular expression.
123
.SH "SEE ALSO"
124
.IR awk (1),
125
.IR ed (1),
126
.IR grep (1),
127
.IR sam (1), 
128
.IR sed (1),
129
.IR regexp (2)