This file is indexed.

/usr/share/doc/flex-old-doc/flex_7.html is in flex-old-doc 2.5.4a-10ubuntu1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
html2
<html>
<!-- Created on February 6, 2012 by texi2html 1.82
texi2html was written by: 
            Lionel Cons <Lionel.Cons@cern.ch> (original author)
            Karl Berry  <karl@freefriends.org>
            Olaf Bachmann <obachman@mathematik.uni-kl.de>
            and many others.
Maintained by: Many creative people.
Send bugs and suggestions to <texi2html-bug@nongnu.org>
-->
<head>
<title>Flex - a scanner generator: 7. Patterns</title>

<meta name="description" content="Flex - a scanner generator: 7. Patterns">
<meta name="keywords" content="Flex - a scanner generator: 7. Patterns">
<meta name="resource-type" content="document">
<meta name="distribution" content="global">
<meta name="Generator" content="texi2html 1.82">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style type="text/css">
<!--
a.summary-letter {text-decoration: none}
blockquote.smallquotation {font-size: smaller}
pre.display {font-family: serif}
pre.format {font-family: serif}
pre.menu-comment {font-family: serif}
pre.menu-preformatted {font-family: serif}
pre.smalldisplay {font-family: serif; font-size: smaller}
pre.smallexample {font-size: smaller}
pre.smallformat {font-family: serif; font-size: smaller}
pre.smalllisp {font-size: smaller}
span.roman {font-family:serif; font-weight:normal;}
span.sansserif {font-family:sans-serif; font-weight:normal;}
ul.toc {list-style: none}
-->
</style>


</head>

<body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">

<a name="Patterns"></a>
<table cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="flex_6.html#Format" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="flex_8.html#Matching" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="flex_6.html#Format" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="flex.html#Top" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="flex_8.html#Matching" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="flex.html#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="flex_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[Index]</td>
<td valign="middle" align="left">[<a href="flex_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Patterns-1"></a>
<h1 class="chapter">7. Patterns</h1>

<p>The patterns in the input are written using an extended
set of regular expressions.  These are:
</p>
<dl compact="compact">
<dt> &lsquo;<samp>x</samp>&rsquo;</dt>
<dd><p>match the character &lsquo;<samp>x</samp>&rsquo;
</p></dd>
<dt> &lsquo;<samp>.</samp>&rsquo;</dt>
<dd><p>any character (byte) except newline
</p></dd>
<dt> &lsquo;<samp>[xyz]</samp>&rsquo;</dt>
<dd><p>a &quot;character class&quot;; in this case, the pattern
matches either an &lsquo;<samp>x</samp>&rsquo;, a &lsquo;<samp>y</samp>&rsquo;, or a &lsquo;<samp>z</samp>&rsquo;
</p></dd>
<dt> &lsquo;<samp>[abj-oZ]</samp>&rsquo;</dt>
<dd><p>a &quot;character class&quot; with a range in it; matches
an &lsquo;<samp>a</samp>&rsquo;, a &lsquo;<samp>b</samp>&rsquo;, any letter from &lsquo;<samp>j</samp>&rsquo; through &lsquo;<samp>o</samp>&rsquo;,
or a &lsquo;<samp>Z</samp>&rsquo;
</p></dd>
<dt> &lsquo;<samp>[^A-Z]</samp>&rsquo;</dt>
<dd><p>a &quot;negated character class&quot;, i.e., any character
but those in the class.  In this case, any
character EXCEPT an uppercase letter.
</p></dd>
<dt> &lsquo;<samp>[^A-Z\n]</samp>&rsquo;</dt>
<dd><p>any character EXCEPT an uppercase letter or
a newline
</p></dd>
<dt> &lsquo;<samp><var>r</var>*</samp>&rsquo;</dt>
<dd><p>zero or more <var>r</var>&rsquo;s, where <var>r</var> is any regular expression
</p></dd>
<dt> &lsquo;<samp><var>r</var>+</samp>&rsquo;</dt>
<dd><p>one or more <var>r</var>&rsquo;s
</p></dd>
<dt> &lsquo;<samp><var>r</var>?</samp>&rsquo;</dt>
<dd><p>zero or one <var>r</var>&rsquo;s (that is, &quot;an optional <var>r</var>&quot;)
</p></dd>
<dt> &lsquo;<samp><var>r</var>{2,5}</samp>&rsquo;</dt>
<dd><p>anywhere from two to five <var>r</var>&rsquo;s
</p></dd>
<dt> &lsquo;<samp><var>r</var>{2,}</samp>&rsquo;</dt>
<dd><p>two or more <var>r</var>&rsquo;s
</p></dd>
<dt> &lsquo;<samp><var>r</var>{4}</samp>&rsquo;</dt>
<dd><p>exactly 4 <var>r</var>&rsquo;s
</p></dd>
<dt> &lsquo;<samp>{<var>name</var>}</samp>&rsquo;</dt>
<dd><p>the expansion of the &quot;<var>name</var>&quot; definition
(see above)
</p></dd>
<dt> &lsquo;<samp>&quot;[xyz]\&quot;foo&quot;</samp>&rsquo;</dt>
<dd><p>the literal string: &lsquo;<samp>[xyz]&quot;foo</samp>&rsquo;
</p></dd>
<dt> &lsquo;<samp>\<var>x</var></samp>&rsquo;</dt>
<dd><p>if <var>x</var> is an &lsquo;<samp>a</samp>&rsquo;, &lsquo;<samp>b</samp>&rsquo;, &lsquo;<samp>f</samp>&rsquo;, &lsquo;<samp>n</samp>&rsquo;, &lsquo;<samp>r</samp>&rsquo;, &lsquo;<samp>t</samp>&rsquo;, or &lsquo;<samp>v</samp>&rsquo;,
then the ANSI-C interpretation of \<var>x</var>.
Otherwise, a literal &lsquo;<samp><var>x</var></samp>&rsquo; (used to escape
operators such as &lsquo;<samp>*</samp>&rsquo;)
</p></dd>
<dt> &lsquo;<samp>\0</samp>&rsquo;</dt>
<dd><p>a NUL character (ASCII code 0)
</p></dd>
<dt> &lsquo;<samp>\123</samp>&rsquo;</dt>
<dd><p>the character with octal value 123
</p></dd>
<dt> &lsquo;<samp>\x2a</samp>&rsquo;</dt>
<dd><p>the character with hexadecimal value <code>2a</code>
</p></dd>
<dt> &lsquo;<samp>(<var>r</var>)</samp>&rsquo;</dt>
<dd><p>match an <var>r</var>; parentheses are used to override
precedence (see below)
</p></dd>
<dt> &lsquo;<samp><var>r</var><var>s</var></samp>&rsquo;</dt>
<dd><p>the regular expression <var>r</var> followed by the
regular expression <var>s</var>; called &quot;concatenation&quot;
</p></dd>
<dt> &lsquo;<samp><var>r</var>|<var>s</var></samp>&rsquo;</dt>
<dd><p>either an <var>r</var> or an <var>s</var>
</p></dd>
<dt> &lsquo;<samp><var>r</var>/<var>s</var></samp>&rsquo;</dt>
<dd><p>an <var>r</var> but only if it is followed by an <var>s</var>.  The text
matched by <var>s</var> is included when determining whether this rule is
the <em>longest match</em>, but is then returned to the input before
the action is executed.  So the action only sees the text matched
by <var>r</var>.  This type of pattern is called <em>trailing context</em>.
(There are some combinations of &lsquo;<samp><var>r</var>/<var>s</var></samp>&rsquo; that <code>flex</code>
cannot match correctly; see notes in the Deficiencies / Bugs section
below regarding &quot;dangerous trailing context&quot;.)
</p></dd>
<dt> &lsquo;<samp>^<var>r</var></samp>&rsquo;</dt>
<dd><p>an <var>r</var>, but only at the beginning of a line (i.e.,
which just starting to scan, or right after a
newline has been scanned).
</p></dd>
<dt> &lsquo;<samp><var>r</var>$</samp>&rsquo;</dt>
<dd><p>an <var>r</var>, but only at the end of a line (i.e., just
before a newline).  Equivalent to &quot;<var>r</var>/\n&quot;.
</p>
<p>Note that flex&rsquo;s notion of &quot;newline&quot; is exactly
whatever the C compiler used to compile flex
interprets &rsquo;\n&rsquo; as; in particular, on some DOS
systems you must either filter out \r&rsquo;s in the
input yourself, or explicitly use <var>r</var>/\r\n for &quot;r$&quot;.
</p></dd>
<dt> &lsquo;<samp>&lt;<var>s</var>&gt;<var>r</var></samp>&rsquo;</dt>
<dd><p>an <var>r</var>, but only in start condition <var>s</var> (see
below for discussion of start conditions)
&lt;<var>s1</var>,<var>s2</var>,<var>s3</var>&gt;<var>r</var>
same, but in any of start conditions <var>s1</var>,
<var>s2</var>, or <var>s3</var>
</p></dd>
<dt> &lsquo;<samp>&lt;*&gt;<var>r</var></samp>&rsquo;</dt>
<dd><p>an <var>r</var> in any start condition, even an exclusive one.
</p></dd>
<dt> &lsquo;<samp>&lt;&lt;EOF&gt;&gt;</samp>&rsquo;</dt>
<dd><p>an end-of-file
&lt;<var>s1</var>,<var>s2</var>&gt;&lt;&lt;EOF&gt;&gt;
an end-of-file when in start condition <var>s1</var> or <var>s2</var>
</p></dd>
</dl>

<p>Note that inside of a character class, all regular
expression operators lose their special meaning except escape
(&rsquo;\&rsquo;) and the character class operators, &rsquo;-&rsquo;, &rsquo;]&rsquo;, and, at
the beginning of the class, &rsquo;^&rsquo;.
</p>
<p>The regular expressions listed above are grouped according
to precedence, from highest precedence at the top to
lowest at the bottom.  Those grouped together have equal
precedence.  For example,
</p>
<table><tr><td>&nbsp;</td><td><pre class="example">foo|bar*
</pre></td></tr></table>

<p>is the same as
</p>
<table><tr><td>&nbsp;</td><td><pre class="example">(foo)|(ba(r*))
</pre></td></tr></table>

<p>since the &rsquo;*&rsquo; operator has higher precedence than
concatenation, and concatenation higher than alternation (&rsquo;|&rsquo;).
This pattern therefore matches <em>either</em> the string &quot;foo&quot; <em>or</em>
the string &quot;ba&quot; followed by zero-or-more r&rsquo;s.  To match
&quot;foo&quot; or zero-or-more &quot;bar&quot;&rsquo;s, use:
</p>
<table><tr><td>&nbsp;</td><td><pre class="example">foo|(bar)*
</pre></td></tr></table>

<p>and to match zero-or-more &quot;foo&quot;&rsquo;s-or-&quot;bar&quot;&rsquo;s:
</p>
<table><tr><td>&nbsp;</td><td><pre class="example">(foo|bar)*
</pre></td></tr></table>

<p>In addition to characters and ranges of characters,
character classes can also contain character class
<em>expressions</em>.  These are expressions enclosed inside &lsquo;<samp>[</samp>&rsquo;: and &lsquo;<samp>:</samp>&rsquo;]
delimiters (which themselves must appear between the &rsquo;[&rsquo;
and &rsquo;]&rsquo; of the character class; other elements may occur
inside the character class, too).  The valid expressions
are:
</p>
<table><tr><td>&nbsp;</td><td><pre class="example">[:alnum:] [:alpha:] [:blank:]
[:cntrl:] [:digit:] [:graph:]
[:lower:] [:print:] [:punct:]
[:space:] [:upper:] [:xdigit:]
</pre></td></tr></table>

<p>These expressions all designate a set of characters
equivalent to the corresponding standard C &lsquo;<samp>isXXX</samp>&rsquo; function.  For
example, &lsquo;<samp>[:alnum:]</samp>&rsquo; designates those characters for which
&lsquo;<samp>isalnum()</samp>&rsquo; returns true - i.e., any alphabetic or numeric.
Some systems don&rsquo;t provide &lsquo;<samp>isblank()</samp>&rsquo;, so flex defines
&lsquo;<samp>[:blank:]</samp>&rsquo; as a blank or a tab.
</p>
<p>For example, the following character classes are all
equivalent:
</p>
<table><tr><td>&nbsp;</td><td><pre class="example">[[:alnum:]]
[[:alpha:][:digit:]
[[:alpha:]0-9]
[a-zA-Z0-9]
</pre></td></tr></table>

<p>If your scanner is case-insensitive (the &lsquo;<samp>-i</samp>&rsquo; flag), then
&lsquo;<samp>[:upper:]</samp>&rsquo; and &lsquo;<samp>[:lower:]</samp>&rsquo; are equivalent to &lsquo;<samp>[:alpha:]</samp>&rsquo;.
</p>
<p>Some notes on patterns:
</p>
<ul class="toc">
<li> - 
A negated character class such as the example
&quot;[^A-Z]&quot; above <em>will match a newline</em> unless &quot;\n&quot; (or an
equivalent escape sequence) is one of the
characters explicitly present in the negated character
class (e.g., &quot;[^A-Z\n]&quot;).  This is unlike how many
other regular expression tools treat negated
character classes, but unfortunately the inconsistency
is historically entrenched.  Matching newlines
means that a pattern like [^&quot;]* can match the
entire input unless there&rsquo;s another quote in the
input.

</li><li> - 
A rule can have at most one instance of trailing
context (the &rsquo;/&rsquo; operator or the &rsquo;$&rsquo; operator).
The start condition, &rsquo;^&rsquo;, and &quot;&lt;&lt;EOF&gt;&gt;&quot; patterns
can only occur at the beginning of a pattern, and,
as well as with &rsquo;/&rsquo; and &rsquo;$&rsquo;, cannot be grouped
inside parentheses.  A &rsquo;^&rsquo; which does not occur at
the beginning of a rule or a &rsquo;$&rsquo; which does not
occur at the end of a rule loses its special
properties and is treated as a normal character.

<p>The following are illegal:
</p>
<table><tr><td>&nbsp;</td><td><pre class="example">foo/bar$
&lt;sc1&gt;foo&lt;sc2&gt;bar
</pre></td></tr></table>

<p>Note that the first of these, can be written
&quot;foo/bar\n&quot;.
</p>
<p>The following will result in &rsquo;$&rsquo; or &rsquo;^&rsquo; being
treated as a normal character:
</p>
<table><tr><td>&nbsp;</td><td><pre class="example">foo|(bar$)
foo|^bar
</pre></td></tr></table>

<p>If what&rsquo;s wanted is a &quot;foo&quot; or a
bar-followed-by-a-newline, the following could be used (the special
&rsquo;|&rsquo; action is explained below):
</p>
<table><tr><td>&nbsp;</td><td><pre class="example">foo      |
bar$     /* action goes here */
</pre></td></tr></table>

<p>A similar trick will work for matching a foo or a
bar-at-the-beginning-of-a-line.
</p></li></ul>

<hr size="6">
<table cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="flex_6.html#Format" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="flex_8.html#Matching" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="flex.html#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="flex_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[Index]</td>
<td valign="middle" align="left">[<a href="flex_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<p>
 <font size="-1">
  This document was generated by <em>Build Daemon user</em> on <em>February 6, 2012</em> using <a href="http://www.nongnu.org/texi2html/"><em>texi2html 1.82</em></a>.
 </font>
 <br>

</p>
</body>
</html>