summaryrefslogtreecommitdiff
path: root/Master/tlpkg/texworks/texworks-help/TeXworks-manual/en/Regularexpressions.html
blob: cce5756177b8e82fe18a15dcf0fa23db90e3fe62 (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
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
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"  
  "http://www.w3.org/TR/html4/loose.dtd">  
<html > 
<head><title>B Regular expressions</title> 
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> 
<meta name="generator" content="TeX4ht (http://www.tug.org/tex4ht/)"> 
<meta name="originator" content="TeX4ht (http://www.tug.org/tex4ht/)"> 
<!-- info,2,imgdir:images/,sec-filename,next,index=2,url-enc,html --> 
<meta name="src" content="index.tex"> 
<link rel="stylesheet" type="text/css" href="index.css"> 
</head><body 
>
<!--l. 5--><p class="noindent" ><div id="container"> <!--l. 5--><div class="crosslinks"><p class="noindent">[<a 
href="CompilingTw.html" >next</a>] [<a 
href="CustomizingTw.html" >prev</a>] [<a 
href="CustomizingTw.html#tailCustomizingTw.html" >prev-tail</a>] [<a 
href="#tailRegularexpressions.html">tail</a>] [<a 
href="index.html#Regularexpressions.html" >up</a>] </p></div>
<!--l. 5--><p class="indent" >   <div class="chapternumber">B</div><h1><a 
 id="x43-51000B"></a>Regular expressions</h1>
<!--l. 8--><p class="indent" >   As T<sub>E</sub>Xworks is built on Qt4, the available regular expressions<a 
 id="dx43-51001"></a>&#8212;which are often
referred to as <b>regexp</b>&#8212;are a subset of those found in Qt4. See the site of
Qt4<span class="footnote-mark"><a 
href="index44.html#fn1x10"><sup class="textsuperscript">1</sup></a></span><a 
 id="x43-51002f1"></a>
for more information. It is possible to find other information about regexps on the
net<span class="footnote-mark"><a 
href="index45.html#fn2x10"><sup class="textsuperscript">2</sup></a></span><a 
 id="x43-51003f2"></a>
or from books. But pay attention that not all systems (programming languages,
editors, &#x2026;) use the same set of instructions; there is no &#8220;standard set&#8221;,
unfortunately.
   <h3 class="sectionHead"><span class="titlemark">B.1   </span> <a 
 id="x43-52000B.1"></a>Introduction</h3>
<a 
 id="dx43-52001"></a>
<!--l. 12--><p class="noindent" >When searching and replacing, one has to define the text to be found. This can be
the text itself (e.g., &#8220;Abracadabra&#8221;), but often it is necessary to define the strings
in a more generic and powerful way to avoid repeating the same operation many
times with only small changes from one time to the next; if, for example, one
wants to replace sequences of the letter <b>a</b> by ones of the letter <b>o</b>, but only those
sequences of 3, 4, 5, 6 or 7 <b>a</b>; this would require repeating (and slightly adjusting)
the find and replace procedure 5 times. Another example: replace all vowels by
<b>§</b>&#8212;again, this would take 5 replace operations. Here come the regular
expressions!
<!--l. 14--><p class="indent" >   A simple character (a or 9) represents itself. But a set of characters can be
defined: <b>[aeiou]</b> will match any vowel, <b>[abcdef]</b> the letters <b>a</b>, <b>b</b>, <b>c</b>, <b>d</b>, <b>e</b>, and <b>f</b>; this
last set can be shortened as <b>[a-f]</b> using &#8220;<b>-</b>&#8221; between the two ends of the range.
This can even be combined: <b>[a-zA-Z0-9]</b> will match all letters and all
numbers.
                                                                          

                                                                          
<!--l. 16--><p class="indent" >   To define a complementary set<span class="footnote-mark"><a 
href="index46.html#fn3x10"><sup class="textsuperscript">3</sup></a></span><a 
 id="x43-52002f3"></a>,
one uses &#8220;<b>^</b>&#8221;: the caret negates the character set if it occurs at the beginning, i.e.,
immediately after the opening square bracket. <b>[^abc]</b> matches anything except <b>a</b>,
<b>b</b>, <b>c</b>.
   <h3 class="sectionHead"><span class="titlemark">B.2   </span> <a 
 id="x43-53000B.2"></a>Codes to represent special sets</h3>
<a 
 id="dx43-53001"></a>
<!--l. 20--><p class="noindent" >When using regexps, one very often has to create a search expession which
represents other strings in a generic way. If you are looking for a string that
matches email addresses, for example, the letters and symbols will vary; still, you
could search for any string which corresponds to the structure of an email address
(<tt>&#x003C;text&#x003E;@&#x003C;text&#x003E;.&#x003C;text&#x003E;</tt>, roughly). To facilitate this, there are abbreviations to
represent letters, figures, symbols, &#x2026;
<!--l. 22--><p class="indent" >   These codes replace and facilitate the definition of sets; for
example, to instead of manually defining the set of digits <b>[0-9]</b>,
one can use &#8220;<b>\d</b>&#8221;. The following table lists the replacement
codes.<span class="footnote-mark"><a 
href="index47.html#fn4x10"><sup class="textsuperscript">4</sup></a></span><a 
 id="x43-53002f4"></a>
                                                                          

                                                                          
<!--l. 25--><p class="noindent" ><!--tex4ht:inline--><div class="tabular">
 <table id="TBL-9" class="tabular" 
cellspacing="0" cellpadding="0"  
><colgroup id="TBL-9-1g"><col 
id="TBL-9-1"><col 
id="TBL-9-2"></colgroup><tr  
 style="vertical-align:baseline;" id="TBL-9-1-"><td  style="white-space:nowrap; text-align:left;" id="TBL-9-1-1"  
class="td11"> <div class="multicolumn"  style="white-space:nowrap; text-align:left;">Element</div> </td><td  style="white-space:wrap; text-align:left;" id="TBL-9-1-2"  
class="td11"> <!--l. 27--><p class="noindent" >Meaning                                                                        </td>
</tr><tr  
 style="vertical-align:baseline;" id="TBL-9-2-"><td  style="white-space:wrap; text-align:left;" id="TBL-9-2-1"  
class="td11"> <!--l. 29--><p class="noindent" ><span class="obeylines-h"><span class="verb"><span 
class="ec-lmtt-12">c</span></span></span>       </td><td  style="white-space:wrap; text-align:left;" id="TBL-9-2-2"  
class="td11"> <!--l. 29--><p class="noindent" >Any character represents itself unless it has a special regexp
  meaning. Thus c matches the character c.                             </td>
</tr><tr  
 style="vertical-align:baseline;" id="TBL-9-3-"><td  style="white-space:wrap; text-align:left;" id="TBL-9-3-1"  
class="td11"> <!--l. 30--><p class="noindent" ><span class="obeylines-h"><span class="verb"><span 
class="ec-lmtt-12">\c</span></span></span>      </td><td  style="white-space:wrap; text-align:left;" id="TBL-9-3-2"  
class="td11"> <!--l. 30--><p class="noindent" >A  special  character  that  follows  a  backslash  matches  the
  character itself except where mentioned below. For example, if
  you wished to match a literal caret at the beginning of a string
  you would write &#8220;<span class="obeylines-h"><span class="verb"><span 
class="ec-lmtt-12">\^</span></span></span>&#8221;.                                                       </td>
</tr><tr  
 style="vertical-align:baseline;" id="TBL-9-4-"><td  style="white-space:wrap; text-align:left;" id="TBL-9-4-1"  
class="td11"> <!--l. 31--><p class="noindent" ><span class="obeylines-h"><span class="verb"><span 
class="ec-lmtt-12">\n</span></span></span>      </td><td  style="white-space:wrap; text-align:left;" id="TBL-9-4-2"  
class="td11"> <!--l. 31--><p class="noindent" >This matches the ASCII line feed character (LF, Unix newline,
  used in T<sub>E</sub>Xworks).                                                                       </td>
</tr><tr  
 style="vertical-align:baseline;" id="TBL-9-5-"><td  style="white-space:wrap; text-align:left;" id="TBL-9-5-1"  
class="td11"> <!--l. 32--><p class="noindent" ><span class="obeylines-h"><span class="verb"><span 
class="ec-lmtt-12">\r</span></span></span>      </td><td  style="white-space:wrap; text-align:left;" id="TBL-9-5-2"  
class="td11"> <!--l. 32--><p class="noindent" >This matches the ASCII carriage return character (CR).          </td>
</tr><tr  
 style="vertical-align:baseline;" id="TBL-9-6-"><td  style="white-space:wrap; text-align:left;" id="TBL-9-6-1"  
class="td11"> <!--l. 33--><p class="noindent" ><span class="obeylines-h"><span class="verb"><span 
class="ec-lmtt-12">\t</span></span></span>      </td><td  style="white-space:wrap; text-align:left;" id="TBL-9-6-2"  
class="td11"> <!--l. 33--><p class="noindent" >This matches the ASCII horizontal tab character (HT).           </td>
</tr><tr  
 style="vertical-align:baseline;" id="TBL-9-7-"><td  style="white-space:wrap; text-align:left;" id="TBL-9-7-1"  
class="td11"> <!--l. 34--><p class="noindent" ><span class="obeylines-h"><span class="verb"><span 
class="ec-lmtt-12">\v</span></span></span>      </td><td  style="white-space:wrap; text-align:left;" id="TBL-9-7-2"  
class="td11"> <!--l. 34--><p class="noindent" >This matches the ASCII vertical tab character (VT; almost
  never used).                                                                    </td>
</tr><tr  
 style="vertical-align:baseline;" id="TBL-9-8-"><td  style="white-space:wrap; text-align:left;" id="TBL-9-8-1"  
class="td11"> <!--l. 35--><p class="noindent" ><span class="obeylines-h"><span class="verb"><span 
class="ec-lmtt-12">\xhhhh</span></span></span>  </td><td  style="white-space:wrap; text-align:left;" id="TBL-9-8-2"  
class="td11"> <!--l. 35--><p class="noindent" >This  matches  the  Unicode  character  corresponding  to  the
  hexadecimal  number  hhhh  (between  0x0000  and  0xFFFF).
  <span class="obeylines-h"><span class="verb"><span 
class="ec-lmtt-12">\0ooo</span></span></span> (i.e.,  zero-ooo)  matches  the  ASCII/Latin-1  character
  corresponding to the octal number ooo (between 0 and 0377).  </td>
</tr><tr  
 style="vertical-align:baseline;" id="TBL-9-9-"><td  style="white-space:wrap; text-align:left;" id="TBL-9-9-1"  
class="td11"> <!--l. 36--><p class="noindent" ><span class="obeylines-h"><span class="verb"><span 
class="ec-lmtt-12">.</span></span></span> <span 
class="ec-lmbx-12">(dot)</span>   </td><td  style="white-space:wrap; text-align:left;" id="TBL-9-9-2"  
class="td11"> <!--l. 36--><p class="noindent" >This matches any character (including newline). So if you want
  to match the dot character iteself, you have to escape it with
  &#8220;<span class="obeylines-h"><span class="verb"><span 
class="ec-lmtt-12">\.</span></span></span>&#8221;.                                                                             </td>
</tr><tr  
 style="vertical-align:baseline;" id="TBL-9-10-"><td  style="white-space:wrap; text-align:left;" id="TBL-9-10-1"  
class="td11"> <!--l. 37--><p class="noindent" ><span class="obeylines-h"><span class="verb"><span 
class="ec-lmtt-12">\d</span></span></span>      </td><td  style="white-space:wrap; text-align:left;" id="TBL-9-10-2"  
class="td11"> <!--l. 37--><p class="noindent" >This matches a digit.                                                        </td>
</tr><tr  
 style="vertical-align:baseline;" id="TBL-9-11-"><td  style="white-space:wrap; text-align:left;" id="TBL-9-11-1"  
class="td11"> <!--l. 38--><p class="noindent" ><span class="obeylines-h"><span class="verb"><span 
class="ec-lmtt-12">\D</span></span></span>      </td><td  style="white-space:wrap; text-align:left;" id="TBL-9-11-2"  
class="td11"> <!--l. 38--><p class="noindent" >This matches a non-digit.                                                  </td>
</tr><tr  
 style="vertical-align:baseline;" id="TBL-9-12-"><td  style="white-space:wrap; text-align:left;" id="TBL-9-12-1"  
class="td11"> <!--l. 39--><p class="noindent" ><span class="obeylines-h"><span class="verb"><span 
class="ec-lmtt-12">\s</span></span></span>      </td><td  style="white-space:wrap; text-align:left;" id="TBL-9-12-2"  
class="td11"> <!--l. 39--><p class="noindent" >This matches a white space.                                               </td>
</tr><tr  
 style="vertical-align:baseline;" id="TBL-9-13-"><td  style="white-space:wrap; text-align:left;" id="TBL-9-13-1"  
class="td11"> <!--l. 40--><p class="noindent" ><span class="obeylines-h"><span class="verb"><span 
class="ec-lmtt-12">\S</span></span></span>      </td><td  style="white-space:wrap; text-align:left;" id="TBL-9-13-2"  
class="td11"> <!--l. 40--><p class="noindent" >This matches a non-white space.                                         </td>
</tr><tr  
 style="vertical-align:baseline;" id="TBL-9-14-"><td  style="white-space:wrap; text-align:left;" id="TBL-9-14-1"  
class="td11"> <!--l. 41--><p class="noindent" ><span class="obeylines-h"><span class="verb"><span 
class="ec-lmtt-12">\w</span></span></span>      </td><td  style="white-space:wrap; text-align:left;" id="TBL-9-14-2"  
class="td11"> <!--l. 41--><p class="noindent" >This matches a word character or &#8220;<span class="obeylines-h"><span class="verb"><span 
class="ec-lmtt-12">_</span></span></span>&#8221;).                                </td>
</tr><tr  
 style="vertical-align:baseline;" id="TBL-9-15-"><td  style="white-space:wrap; text-align:left;" id="TBL-9-15-1"  
class="td11"> <!--l. 42--><p class="noindent" ><span class="obeylines-h"><span class="verb"><span 
class="ec-lmtt-12">\W</span></span></span>      </td><td  style="white-space:wrap; text-align:left;" id="TBL-9-15-2"  
class="td11"> <!--l. 42--><p class="noindent" >This matches a non-word character.                                     </td>
</tr><tr  
 style="vertical-align:baseline;" id="TBL-9-16-"><td  style="white-space:wrap; text-align:left;" id="TBL-9-16-1"  
class="td11"> <!--l. 43--><p class="noindent" ><span class="obeylines-h"><span class="verb"><span 
class="ec-lmtt-12">\1</span></span></span><span 
class="ec-lmbx-12">, </span><span 
class="ec-lmbx-12">&#x2026;</span>     </td><td  style="white-space:wrap; text-align:left;" id="TBL-9-16-2"  
class="td11"> <!--l. 43--><p class="noindent" >The  n-th  back-reference,  e.g.  <span class="obeylines-h"><span class="verb"><span 
class="ec-lmtt-12">\1</span></span></span>,  <span class="obeylines-h"><span class="verb"><span 
class="ec-lmtt-12">\2</span></span></span>,  etc.;  used  in  the
  replacement string with capturing patterns&#8212;see below            </td>

</tr><tr  
 style="vertical-align:baseline;" id="TBL-9-17-"><td  style="white-space:wrap; text-align:left;" id="TBL-9-17-1"  
class="td11">         </td></tr></table></div>
<!--l. 48--><p class="indent" >   Using these abbreviations is better than describing the set, because the
abbreviations remain valid in different alphabets.
<!--l. 50--><p class="indent" >   Pay attention that the end of line is often taken as a white space. Under T<sub>E</sub>Xworks the
end of line is referred to by &#8220;<span class="obeylines-h"><span class="verb"><span 
class="ec-lmtt-12">\n</span></span></span>&#8221;.
   <h3 class="sectionHead"><span class="titlemark">B.3   </span> <a 
 id="x43-54000B.3"></a>Repetition</h3>
<a 
 id="dx43-54001"></a>
<!--l. 55--><p class="noindent" >One doesn&#8217;t work only on single letters, digits, symbols; most of the time, these
are repeated (e.g., a number is a repetition of digits and symbols&#8212;in the right
order).
<!--l. 58--><p class="indent" >   To show the number of repetitions, one uses a so called &#8220;quantifier&#8221;: <b>a{1,1}</b>
means at least one and only one <b>a</b>, <b>a{3,7}</b> means between at least 3 and at most 7
<b>a</b>; <b>{1,1}</b> is redundant, of course, so <b>a{1,1}</b> = <b>a</b>.
                                                                          

                                                                          
<!--l. 60--><p class="indent" >   This can be combined with the set notation: <b>[0-9]{1,2}</b> will correspond to at
least one digit and at most two, the integer numbers between 0 and 99. But this
will match any group of 1 or 2 digits within any arbitrary string (which may have
a lot of text before and after the integer); if we want this to match only if the
whole string consists <em>entirely</em> of 1 or 2 digits (without any other characters
preceding or following them), we can rewrite the regular expression to read
<b>^[0-9]{1,2}$</b>; here, the <b>^</b> specifies that any match must start at the first character
of the string, while the <b>$</b> says that any matching substring must end
at the last character of the string, so the string can only be comprised
of one or two digits (<b>^</b> and <b>$</b> are so-called &#8220;assertions&#8221;&#8212;more on them
later).
<!--l. 62--><p class="indent" >   Here is a table of quantifiers.<span class="footnote-mark"><a 
href="index48.html#fn5x10"><sup class="textsuperscript">5</sup></a></span><a 
 id="x43-54002f5"></a>
E represents an arbitrary expression (letter, abbreviation, set).
<!--l. 65--><p class="noindent" ><!--tex4ht:inline--><div class="tabular">
 <table id="TBL-10" class="tabular" 
cellspacing="0" cellpadding="0"  
><colgroup id="TBL-10-1g"><col 
id="TBL-10-1"><col 
id="TBL-10-2"></colgroup><tr  
 style="vertical-align:baseline;" id="TBL-10-1-"><td  style="white-space:wrap; text-align:left;" id="TBL-10-1-1"  
class="td11"> <!--l. 67--><p class="noindent" ><span class="obeylines-h"><span class="verb"><span 
class="ec-lmtt-12">E{n,m}</span></span></span>  </td><td  style="white-space:wrap; text-align:left;" id="TBL-10-1-2"  
class="td11"> <!--l. 67--><p class="noindent" >Matches at least <b>n</b> occurrences of the expression and at most
  <b>m</b> occurrences of the expression.                                         </td>
</tr><tr  
 style="vertical-align:baseline;" id="TBL-10-2-"><td  style="white-space:wrap; text-align:left;" id="TBL-10-2-1"  
class="td11"> <!--l. 68--><p class="noindent" ><span class="obeylines-h"><span class="verb"><span 
class="ec-lmtt-12">E{n}</span></span></span>     </td><td  style="white-space:wrap; text-align:left;" id="TBL-10-2-2"  
class="td11"> <!--l. 68--><p class="noindent" >Matches exactly <b>n</b> occurrences of the expression. This is the
  same <b>E{n,n}</b> or as repeating the expression n times.               </td>
</tr><tr  
 style="vertical-align:baseline;" id="TBL-10-3-"><td  style="white-space:wrap; text-align:left;" id="TBL-10-3-1"  
class="td11"> <!--l. 69--><p class="noindent" ><span class="obeylines-h"><span class="verb"><span 
class="ec-lmtt-12">E{n,}</span></span></span>    </td><td  style="white-space:wrap; text-align:left;" id="TBL-10-3-2"  
class="td11"> <!--l. 69--><p class="noindent" >Matches at least <b>n</b> occurrences of the expression.                   </td>
</tr><tr  
 style="vertical-align:baseline;" id="TBL-10-4-"><td  style="white-space:wrap; text-align:left;" id="TBL-10-4-1"  
class="td11"> <!--l. 70--><p class="noindent" ><span class="obeylines-h"><span class="verb"><span 
class="ec-lmtt-12">E{,m}</span></span></span>    </td><td  style="white-space:wrap; text-align:left;" id="TBL-10-4-2"  
class="td11"> <!--l. 70--><p class="noindent" >Matches at most <b>m</b> occurrences of the expression.                  </td>
</tr><tr  
 style="vertical-align:baseline;" id="TBL-10-5-"><td  style="white-space:wrap; text-align:left;" id="TBL-10-5-1"  
class="td11"> <!--l. 71--><p class="noindent" ><span class="obeylines-h"><span class="verb"><span 
class="ec-lmtt-12">E?</span></span></span>       </td><td  style="white-space:wrap; text-align:left;" id="TBL-10-5-2"  
class="td11"> <!--l. 71--><p class="noindent" >Matches zero or one occurrence of E. This quantifier effectively
  means <em>the expression is optional</em> (it may be present, but doesn&#8217;t
  have to). It is the same as <b>E{0,1}</b>.                                       </td>
</tr><tr  
 style="vertical-align:baseline;" id="TBL-10-6-"><td  style="white-space:wrap; text-align:left;" id="TBL-10-6-1"  
class="td11"> <!--l. 72--><p class="noindent" ><span class="obeylines-h"><span class="verb"><span 
class="ec-lmtt-12">E+</span></span></span>       </td><td  style="white-space:wrap; text-align:left;" id="TBL-10-6-2"  
class="td11"> <!--l. 72--><p class="noindent" >Matches one or more occurrences of E. This is the same as
  <b>E{1,}</b>.                                                                           </td>
</tr><tr  
 style="vertical-align:baseline;" id="TBL-10-7-"><td  style="white-space:wrap; text-align:left;" id="TBL-10-7-1"  
class="td11"> <!--l. 73--><p class="noindent" ><span class="obeylines-h"><span class="verb"><span 
class="ec-lmtt-12">E*</span></span></span>       </td><td  style="white-space:wrap; text-align:left;" id="TBL-10-7-2"  
class="td11"> <!--l. 73--><p class="noindent" >Matches zero or more occurrences of E. This is the same as
  <b>E{0,}</b>. Beware, the <b>*</b> quantifier is often used by mistake instead
  of the <b>+</b> quantifier. Since it matches zero or more occurrences,
  it will match even if the expression is not present in the string.  </td>

</tr><tr  
 style="vertical-align:baseline;" id="TBL-10-8-"><td  style="white-space:wrap; text-align:left;" id="TBL-10-8-1"  
class="td11">         </td></tr></table></div>
   <h3 class="sectionHead"><span class="titlemark">B.4   </span> <a 
 id="x43-55000B.4"></a>Alternatives and assertions</h3>
<a 
 id="dx43-55001"></a>
<!--l. 81--><p class="noindent" >When searching, it is often necessary to search for alternatives, e.g., apple, pear,
or cherry, but not pineapple. To separate the alternatives, one uses <b>|</b>:
apple|pear|cherry. But this will not prevent to find pineapple, so we have to
specify that apple should be standalone, a whole word (as is often called in the
                                                                          

                                                                          
search dialog boxes).
<!--l. 83--><p class="indent" >   To specify that a string should be considered standalone, we specify that it
is surrounded by word separators/boundaries (begin/end of sentence,
space), like <b>\bapple\b</b>. For our alternatives example we will <b>group</b> them by
parentheses and add the boundaries <b>\b(apple|pear|cherry)\b</b>. Apart from <b>\b</b>
we have already seen <b>^</b> and <b>$</b> which mark the boundaries of the whole
string.
<!--l. 85--><p class="indent" >   Here a table of the &#8220;assertions&#8221; which do not correspond to
actual characters and will never be part of the result of a search.
<span class="footnote-mark"><a 
href="index49.html#fn6x10"><sup class="textsuperscript">6</sup></a></span><a 
 id="x43-55002f6"></a>
<!--l. 88--><p class="noindent" ><!--tex4ht:inline--><div class="tabular">
 <table id="TBL-11" class="tabular" 
cellspacing="0" cellpadding="0"  
><colgroup id="TBL-11-1g"><col 
id="TBL-11-1"><col 
id="TBL-11-2"></colgroup><tr  
 style="vertical-align:baseline;" id="TBL-11-1-"><td  style="white-space:wrap; text-align:left;" id="TBL-11-1-1"  
class="td11"> <!--l. 90--><p class="noindent" ><span class="obeylines-h"><span class="verb"><span 
class="ec-lmtt-12">^</span></span></span>       </td><td  style="white-space:wrap; text-align:left;" id="TBL-11-1-2"  
class="td11"> <!--l. 90--><p class="noindent" >The caret signifies the beginning of the string. If you wish to
  match a literal <b>^</b>, you must escape it by writing <span class="obeylines-h"><span class="verb"><span 
class="ec-lmtt-12">\^</span></span></span>           </td>
</tr><tr  
 style="vertical-align:baseline;" id="TBL-11-2-"><td  style="white-space:wrap; text-align:left;" id="TBL-11-2-1"  
class="td11"> <!--l. 91--><p class="noindent" ><span class="obeylines-h"><span class="verb"><span 
class="ec-lmtt-12">$</span></span></span>        </td><td  style="white-space:wrap; text-align:left;" id="TBL-11-2-2"  
class="td11"> <!--l. 91--><p class="noindent" >The dollar signifies the end of the string. If you wish to match
  a literal <b>$</b>, you must escape it by writing <span class="obeylines-h"><span class="verb"><span 
class="ec-lmtt-12">\$</span></span></span>                </td>
</tr><tr  
 style="vertical-align:baseline;" id="TBL-11-3-"><td  style="white-space:wrap; text-align:left;" id="TBL-11-3-1"  
class="td11"> <!--l. 92--><p class="noindent" ><span class="obeylines-h"><span class="verb"><span 
class="ec-lmtt-12">\b</span></span></span>       </td><td  style="white-space:wrap; text-align:left;" id="TBL-11-3-2"  
class="td11"> <!--l. 92--><p class="noindent" >A word boundary.                                                            </td>
</tr><tr  
 style="vertical-align:baseline;" id="TBL-11-4-"><td  style="white-space:wrap; text-align:left;" id="TBL-11-4-1"  
class="td11"> <!--l. 93--><p class="noindent" ><span class="obeylines-h"><span class="verb"><span 
class="ec-lmtt-12">\B</span></span></span>       </td><td  style="white-space:wrap; text-align:left;" id="TBL-11-4-2"  
class="td11"> <!--l. 93--><p class="noindent" >A non-word boundary. This assertion is true wherever <span class="obeylines-h"><span class="verb"><span 
class="ec-lmtt-12">\b</span></span></span> is
  false.                                                                             </td>
</tr><tr  
 style="vertical-align:baseline;" id="TBL-11-5-"><td  style="white-space:wrap; text-align:left;" id="TBL-11-5-1"  
class="td11"> <!--l. 94--><p class="noindent" ><span class="obeylines-h"><span class="verb"><span 
class="ec-lmtt-12">(?=E)</span></span></span>    </td><td  style="white-space:wrap; text-align:left;" id="TBL-11-5-2"  
class="td11"> <!--l. 94--><p class="noindent" >Positive lookahead. This assertion is true if the expression <b>E</b>
  matches at this point.                                                       </td>
</tr><tr  
 style="vertical-align:baseline;" id="TBL-11-6-"><td  style="white-space:wrap; text-align:left;" id="TBL-11-6-1"  
class="td11"> <!--l. 95--><p class="noindent" ><span class="obeylines-h"><span class="verb"><span 
class="ec-lmtt-12">(?!E)</span></span></span>    </td><td  style="white-space:wrap; text-align:left;" id="TBL-11-6-2"  
class="td11"> <!--l. 95--><p class="noindent" >Negative lookahead. This assertion is true if the expression <b>E</b>
  does not match at this point.                                             </td>

</tr><tr  
 style="vertical-align:baseline;" id="TBL-11-7-"><td  style="white-space:wrap; text-align:left;" id="TBL-11-7-1"  
class="td11">         </td></tr></table></div>
<!--l. 100--><p class="indent" >   Notice the different meanings of <b>^</b> as assertion and as negation inside a
character set!
   <h3 class="sectionHead"><span class="titlemark">B.5   </span> <a 
 id="x43-56000B.5"></a>Final notes</h3>
<!--l. 104--><p class="noindent" >Using rexexp is very powerful, but also quite dangerous; you could change your
text at unseen places and sometimes reverting to the previous situation
is not possible entirely. If you immediately see the error, you can try
<span class="keystroke">Ctrl</span><span class="keystroke">Z</span>.
<!--l. 106--><p class="indent" >   Showing how to exploit the full power of regexp would require much more than
this extremely short summary; in fact it would require a full manual on it
own.
<!--l. 108--><p class="indent" >   Also note that there are some limits in the implementation of regexps in T<sub>E</sub>Xworks; in
particular, the assertions (^ and $) only consider the whole file, and there are no
                                                                          

                                                                          
look-behind assertions.
<!--l. 110--><p class="indent" >   Finally, do not forget to &#8220;tick&#8221; the regexp option when using them in
the <em>Find</em> and <em>Replace</em> dialogs and to un-tick the option when not using
regexps.
                                                                          

                                                                          
                                                                          

                                                                          
                                                                          

                                                                          
   <!--l. 5--><div class="crosslinks"><p class="noindent">[<a 
href="CompilingTw.html" >next</a>] [<a 
href="CustomizingTw.html" >prev</a>] [<a 
href="CustomizingTw.html#tailCustomizingTw.html" >prev-tail</a>] [<a 
href="Regularexpressions.html" >front</a>] [<a 
href="index.html#Regularexpressions.html" >up</a>] </p></div>
<!--l. 5--><p class="indent" >   <a 
 id="tailRegularexpressions.html"></a>  </div> 
</body></html>