-
Notifications
You must be signed in to change notification settings - Fork 68
/
x15.10.html
2978 lines (2974 loc) · 111 KB
/
x15.10.html
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
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html class="split chapter"><head><meta charset="utf-8"><title>15.10 RegExp (Regular Expression) Objects # Ⓣ Ⓔ ① Ⓐ — Annotated ES5</title><link rel="stylesheet" href="style.css"><link href="x15.9.html" title="15.9 Date Objects " rel="prev">
<link href="spec.html" title="TOC" rel="index">
<link href="x15.11.html" title="15.11 Error Objects " rel="next">
</head><body><div class="head">
<h2 id="top">Annotated ECMAScript 5.1 <span id="timestamp"></span></h2>
<div id="mascot-treehouse">
<img id="mascot" align="left" src="js-mascot.svg" alt=""><img id="bubble" src="bubble.svg" alt=""></div>
<p id="slogan">‟Ex igne vita”</p>
<div id="annotations"></div>
<script src="timestamp.js"></script></div>
<nav>
<a href="x15.9.html">← 15.9 Date Objects </a> –
<a href="spec.html" class="toc-nav">TOC</a> –
<a href="x15.11.html">15.11 Error Objects →</a>
<ol class="toc"><li><ol><li><a href="x15.10.html#x15.10" id="x15.10-toc">15.10 RegExp (Regular Expression) Objects</a>
<b class="erra">Ⓔ</b> <b class="rev1">①</b> <b class="anno">Ⓐ</b> <ol><li><a href="x15.10.html#x15.10.1" id="x15.10.1-toc">15.10.1 Patterns</a> <b class="erra">Ⓔ</b> <b class="rev1">①</b> <b class="anno">Ⓐ</b> </li><li><a href="x15.10.html#x15.10.2" id="x15.10.2-toc">15.10.2 Pattern Semantics</a>
<b class="erra">Ⓔ</b> <b class="rev1">①</b> <b class="anno">Ⓐ</b> <ol><li><a href="x15.10.html#x15.10.2.1" id="x15.10.2.1-toc">15.10.2.1 Notation</a> <b class="erra">Ⓔ</b> <b class="rev1">①</b> <b class="anno">Ⓐ</b> </li><li><a href="x15.10.html#x15.10.2.2" id="x15.10.2.2-toc">15.10.2.2 Pattern</a> <b class="erra">Ⓔ</b> <b class="rev1">①</b> <b class="anno">Ⓐ</b> </li><li><a href="x15.10.html#x15.10.2.3" id="x15.10.2.3-toc">15.10.2.3 Disjunction</a> <b class="erra">Ⓔ</b> <b class="rev1">①</b> <b class="anno">Ⓐ</b> </li><li><a href="x15.10.html#x15.10.2.4" id="x15.10.2.4-toc">15.10.2.4 Alternative</a> <b class="erra">Ⓔ</b> <b class="rev1">①</b> <b class="anno">Ⓐ</b> </li><li><a href="x15.10.html#x15.10.2.5" id="x15.10.2.5-toc">15.10.2.5 Term</a> <b class="erra">Ⓔ</b> <b class="rev1">①</b> <b class="anno">Ⓐ</b> </li><li><a href="x15.10.html#x15.10.2.6" id="x15.10.2.6-toc">15.10.2.6 Assertion</a> <b class="erra">Ⓔ</b> <b class="rev1">①</b> <b class="anno">Ⓐ</b> </li><li><a href="x15.10.html#x15.10.2.7" id="x15.10.2.7-toc">15.10.2.7 Quantifier</a> <b class="erra">Ⓔ</b> <b class="rev1">①</b> <b class="anno">Ⓐ</b> </li><li><a href="x15.10.html#x15.10.2.8" id="x15.10.2.8-toc">15.10.2.8 Atom</a> <b class="erra">Ⓔ</b> <b class="rev1">①</b> <b class="anno">Ⓐ</b> </li><li><a href="x15.10.html#x15.10.2.9" id="x15.10.2.9-toc">15.10.2.9 AtomEscape</a> <b class="erra">Ⓔ</b> <b class="rev1">①</b> <b class="anno">Ⓐ</b> </li><li><a href="x15.10.html#x15.10.2.10" id="x15.10.2.10-toc">15.10.2.10 CharacterEscape</a> <b class="erra">Ⓔ</b> <b class="rev1">①</b> <b class="anno">Ⓐ</b> </li><li><a href="x15.10.html#x15.10.2.11" id="x15.10.2.11-toc">15.10.2.11 DecimalEscape</a> <b class="erra">Ⓔ</b> <b class="rev1">①</b> <b class="anno">Ⓐ</b> </li><li><a href="x15.10.html#x15.10.2.12" id="x15.10.2.12-toc">15.10.2.12 CharacterClassEscape</a> <b class="erra">Ⓔ</b> <b class="rev1">①</b> <b class="anno">Ⓐ</b> </li><li><a href="x15.10.html#x15.10.2.13" id="x15.10.2.13-toc">15.10.2.13 CharacterClass</a> <b class="erra">Ⓔ</b> <b class="rev1">①</b> <b class="anno">Ⓐ</b> </li><li><a href="x15.10.html#x15.10.2.14" id="x15.10.2.14-toc">15.10.2.14 ClassRanges</a> <b class="erra">Ⓔ</b> <b class="rev1">①</b> <b class="anno">Ⓐ</b> </li><li><a href="x15.10.html#x15.10.2.15" id="x15.10.2.15-toc">15.10.2.15 NonemptyClassRanges</a> <b class="erra">Ⓔ</b> <b class="rev1">①</b> <b class="anno">Ⓐ</b> </li><li><a href="x15.10.html#x15.10.2.16" id="x15.10.2.16-toc">15.10.2.16 NonemptyClassRangesNoDash</a> <b class="erra">Ⓔ</b> <b class="rev1">①</b> <b class="anno">Ⓐ</b> </li><li><a href="x15.10.html#x15.10.2.17" id="x15.10.2.17-toc">15.10.2.17 ClassAtom</a> <b class="erra">Ⓔ</b> <b class="rev1">①</b> <b class="anno">Ⓐ</b> </li><li><a href="x15.10.html#x15.10.2.18" id="x15.10.2.18-toc">15.10.2.18 ClassAtomNoDash</a> <b class="erra">Ⓔ</b> <b class="rev1">①</b> <b class="anno">Ⓐ</b> </li><li><a href="x15.10.html#x15.10.2.19" id="x15.10.2.19-toc">15.10.2.19 ClassEscape</a> <b class="erra">Ⓔ</b> <b class="rev1">①</b> <b class="anno">Ⓐ</b> </li></ol></li><li><a href="x15.10.html#x15.10.3" id="x15.10.3-toc">15.10.3 The RegExp Constructor Called as a Function</a>
<b class="erra">Ⓔ</b> <b class="rev1">①</b> <b class="anno">Ⓐ</b> <ol><li><a href="x15.10.html#x15.10.3.1" id="x15.10.3.1-toc">15.10.3.1 RegExp(pattern, flags)</a> <b class="erra">Ⓔ</b> <b class="rev1">①</b> <b class="anno">Ⓐ</b> </li></ol></li><li><a href="x15.10.html#x15.10.4" id="x15.10.4-toc">15.10.4 The RegExp Constructor</a>
<b class="erra">Ⓔ</b> <b class="rev1">①</b> <b class="anno">Ⓐ</b> <ol><li><a href="x15.10.html#x15.10.4.1" id="x15.10.4.1-toc">15.10.4.1 new RegExp(pattern, flags)</a> <b class="erra">Ⓔ</b> <b class="rev1">①</b> <b class="anno">Ⓐ</b> </li></ol></li><li><a href="x15.10.html#x15.10.5" id="x15.10.5-toc">15.10.5 Properties of the RegExp Constructor</a>
<b class="erra">Ⓔ</b> <b class="rev1">①</b> <b class="anno">Ⓐ</b> <ol><li><a href="x15.10.html#x15.10.5.1" id="x15.10.5.1-toc">15.10.5.1 RegExp.prototype</a> <b class="erra">Ⓔ</b> <b class="rev1">①</b> <b class="anno">Ⓐ</b> </li></ol></li><li><a href="x15.10.html#x15.10.6" id="x15.10.6-toc">15.10.6 Properties of the RegExp Prototype Object</a>
<b class="erra">Ⓔ</b> <b class="rev1">①</b> <b class="anno">Ⓐ</b> <ol><li><a href="x15.10.html#x15.10.6.1" id="x15.10.6.1-toc">15.10.6.1 RegExp.prototype.constructor</a> <b class="erra">Ⓔ</b> <b class="rev1">①</b> <b class="anno">Ⓐ</b> </li><li><a href="x15.10.html#x15.10.6.2" id="x15.10.6.2-toc">15.10.6.2 RegExp.prototype.exec(string)</a> <b class="erra">Ⓔ</b> <b class="rev1">①</b> <b class="anno">Ⓐ</b> </li><li><a href="x15.10.html#x15.10.6.3" id="x15.10.6.3-toc">15.10.6.3 RegExp.prototype.test(string)</a> <b class="erra">Ⓔ</b> <b class="rev1">①</b> <b class="anno">Ⓐ</b> </li><li><a href="x15.10.html#x15.10.6.4" id="x15.10.6.4-toc">15.10.6.4 RegExp.prototype.toString()</a> <b class="erra">Ⓔ</b> <b class="rev1">①</b> <b class="anno">Ⓐ</b> </li></ol></li><li><a href="x15.10.html#x15.10.7" id="x15.10.7-toc">15.10.7 Properties of RegExp Instances</a>
<b class="erra">Ⓔ</b> <b class="rev1">①</b> <b class="anno">Ⓐ</b> <ol><li><a href="x15.10.html#x15.10.7.1" id="x15.10.7.1-toc">15.10.7.1 source</a> <b class="erra">Ⓔ</b> <b class="rev1">①</b> <b class="anno">Ⓐ</b> </li><li><a href="x15.10.html#x15.10.7.2" id="x15.10.7.2-toc">15.10.7.2 global</a> <b class="erra">Ⓔ</b> <b class="rev1">①</b> <b class="anno">Ⓐ</b> </li><li><a href="x15.10.html#x15.10.7.3" id="x15.10.7.3-toc">15.10.7.3 ignoreCase</a> <b class="erra">Ⓔ</b> <b class="rev1">①</b> <b class="anno">Ⓐ</b> </li><li><a href="x15.10.html#x15.10.7.4" id="x15.10.7.4-toc">15.10.7.4 multiline</a> <b class="erra">Ⓔ</b> <b class="rev1">①</b> <b class="anno">Ⓐ</b> </li><li><a href="x15.10.html#x15.10.7.5" id="x15.10.7.5-toc">15.10.7.5 lastIndex</a> <b class="erra">Ⓔ</b> <b class="rev1">①</b> <b class="anno">Ⓐ</b> </li></ol></li></ol></li></ol></li></ol></nav>
<h3 id="x15.10" class="splitme">15.10 RegExp (Regular Expression) Objects <a href="#x15.10">#</a> <a href="#x15.10-toc" class="bak">Ⓣ</a> <b class="erra">Ⓔ</b> <b class="rev1">①</b> <b class="anno">Ⓐ</b></h3>
<p>
A
RegExp object contains a regular expression and the associated
flags.</p>
<p><b class="note">NOTE</b> The
form and functionality of regular expressions is modelled after the
regular expression facility in the Perl 5 programming language.</p>
<h4 id="x15.10.1">15.10.1 Patterns <a href="#x15.10.1">#</a> <a href="#x15.10.1-toc" class="bak">Ⓣ</a> <b class="erra">Ⓔ</b> <b class="rev1">①</b> <b class="anno">Ⓐ</b></h4>
<p>
The
<code><b>RegExp</b></code> constructor
applies the following grammar to the input pattern String. An error
occurs if the grammar cannot interpret the String as an expansion of
<i>Pattern</i>.</p>
<p class="tiny-btm">
<b>Syntax</b></p>
<p class="keep">
<i>Pattern </i><b>::</b></p>
<p class="def1-btm">
<i>Disjunction</i></p>
<p class="keep">
<i>Disjunction </i><b>::</b></p>
<p class="def1-btm">
<i>Alternative<br>
Alternative </i><code><b>|</b></code> <i>Disjunction</i></p>
<p class="keep">
<i>Alternative </i><b>::</b></p>
<p class="def1-btm">
[empty]<i><br>Alternative
Term</i></p>
<p class="keep">
<i>Term </i><b>::</b></p>
<p class="def1-btm">
<i>Assertion<br>Atom<br>Atom
Quantifier</i></p>
<p class="keep">
<i>Assertion </i><b>::</b></p>
<p class="def1-btm">
<code><b>^</b></code> <i><br></i><code><b>$</b></code> <i><br></i><code><b>\
b</b></code> <i><br></i><code><b>\
B<br>(</b></code> <i><b>
</b></i><code><b>?</b></code> <i><b>
</b></i><code><b>=</b></code> <i><b>
</b>Disjunction </i><code><b>)</b></code> <i><br></i><code><b>(</b></code> <i><b>
</b></i><code><b>?</b></code> <i><b>
</b></i><code><b>!</b></code> <i><b>
</b>Disjunction </i><code><b>)</b></code></p>
<p class="keep">
<i>Quantifier </i><b>::</b></p>
<p class="def1-btm">
<i>QuantifierPrefix<br>QuantifierPrefix</i><code><b>
?</b></code></p>
<p class="keep">
<i>QuantifierPrefix </i><b>::</b></p>
<p class="def1-btm">
<code><b>*<br>+</b></code> <i><br></i><code><b>?</b></code> <i><br></i><code><b>{</b></code> <i>DecimalDigits </i><code><b>}</b></code> <i><br></i><code><b>{</b></code> <i>DecimalDigits<b>
</b></i><code><b>,</b></code> <i><b>
</b></i><code><b>}</b></code> <i><br></i><code><b>{</b></code> <i>DecimalDigits<b>
</b></i><code><b>,</b></code> <i>DecimalDigits </i><code><b>}</b></code></p>
<p class="keep">
<i>Atom </i><b>::</b></p>
<p class="def1-btm">
<i>PatternCharacter<br></i><code>.</code><i><br></i><code><b>\
</b></code> <i>AtomEscape<br>CharacterClass</i><code><b><br>(</b></code> <i><b>
</b>Disjunction </i><code><b>)</b></code> <i><br></i><code><b>(</b></code> <i><b>
</b></i><code><b>?</b></code> <i><b>
</b></i><code><b>:</b></code> <i><b>
</b>Disjunction </i><code><b>)</b></code></p>
<p class="keep">
<i>PatternCharacter </i><b>::</b><i>SourceCharacter </i><b>but
not</b><i> </i><b>any
of:</b></p>
<p class="def1-btm">
<i>^ </i><code><b>$
\ . * + ? ( ) [ ] { } |</b></code></p>
<p class="keep">
<i>AtomEscape </i><b>::</b></p>
<p class="def1-btm">
<i>DecimalEscape<br>CharacterEscape<br>CharacterClassEscape</i></p>
<p class="keep">
<i>CharacterEscape </i><b>::</b></p>
<p class="def1-btm">
<i>ControlEscape<br></i><code><b>c
</b></code> <i>ControlLetter<br>HexEscapeSequence<br>UnicodeEscapeSequence<br>IdentityEscape</i></p>
<p class="keep">
<i>ControlEscape </i><b>::</b><i><b>
</b></i><b>one
of</b></p>
<p class="def1-btm">
<code><b>f
n r t v</b></code></p>
<p class="keep">
<i>ControlLetter </i><b>::</b><i><b>
</b></i><b>one
of</b></p>
<p class="def1-btm">
<code><b>a
b c d e f g h i j k l m n o p q r s t u v w x
y z<br>A B C D E F G H I J K L M N O P Q R S T
U V W X Y Z</b></code></p>
<p class="keep">
<i>IdentityEscape </i><b>::</b></p>
<p class="def1-btm">
<i>SourceCharacter </i><b>but
not</b><i><b>
</b>IdentifierPart<br></i><ZWJ><br><ZWNJ></p>
<p class="keep">
<i>DecimalEscape </i><b>::</b></p>
<p class="def1-btm">
<i>DecimalIntegerLiteral </i>[<a href="x5.html#lookahead-not-in">lookahead
<span class="symbol">∉</span></a>
DecimalDigit]</p>
<p class="keep">
<i>CharacterClassEscape </i><b>::</b><i><b>
</b></i><b>one
of</b></p>
<p class="def1-btm">
<code><b>d
D s S w W</b></code></p>
<p class="keep">
<i>CharacterClass </i><b>::</b></p>
<p class="def1-btm">
<code><b>[
</b></code>[<a href="x5.html#lookahead-not-in">lookahead
<span class="symbol">∉</span></a>
{<code><b>^</b></code>}]<code><b>
</b></code> <i>ClassRanges</i><code><b>
]</b></code> <i><br></i><code><b>[
^</b></code> <i>ClassRanges</i><code><b>
]</b></code></p>
<p class="keep">
<i>ClassRanges </i><b>::</b></p>
<p class="def1-btm">
[empty]<i><br>NonemptyClassRanges</i></p>
<p class="keep">
<i>NonemptyClassRanges </i><b>::</b></p>
<p class="def1-btm">
<i>ClassAtom<br>ClassAtom
NonemptyClassRangesNoDash<br>ClassAtom</i><code><b>
-</b></code> <i>ClassAtom ClassRanges</i></p>
<p class="keep">
<i>NonemptyClassRangesNoDash </i><b>::</b></p>
<p class="def1-btm">
<i>ClassAtom<br>ClassAtomNoDash
NonemptyClassRangesNoDash<br>ClassAtomNoDash</i><code><b>
-</b></code> <i>ClassAtom ClassRanges</i></p>
<p class="keep">
<i>ClassAtom </i><b>::</b></p>
<p class="def1-btm">
<code><b>-</b></code> <i><br>ClassAtomNoDash</i></p>
<p class="keep">
<i>ClassAtomNoDash </i><b>::</b></p>
<p class="def1-btm">
<i>SourceCharacter </i><b>but
not</b><i> </i><b>one
of</b><i> </i><code><b>\</b></code> <b>or</b> <code><b>]</b></code> <b>or</b> <code><b>-</b></code> <i><br></i><code>\
</code><i>ClassEscape</i></p>
<p class="keep">
<i>ClassEscape </i><b>::</b></p>
<p class="def1-btm">
<i>DecimalEscape<br></i><code><b>b</b></code> <i><br>CharacterEscape</i><code><b><br></b></code> <i>CharacterClassEscape</i></p>
<h4 id="x15.10.2">15.10.2 Pattern Semantics <a href="#x15.10.2">#</a> <a href="#x15.10.2-toc" class="bak">Ⓣ</a> <b class="erra">Ⓔ</b> <b class="rev1">①</b> <b class="anno">Ⓐ</b></h4>
<p>
A
regular expression pattern is converted into an internal procedure
using the process described below. An implementation is encouraged
to use more efficient algorithms than the ones listed below, as long
as the results are the same. The internal procedure is used as the
value of a RegExp object’s [[Match]] internal property.</p>
<h5 id="x15.10.2.1">15.10.2.1 Notation <a href="#x15.10.2.1">#</a> <a href="#x15.10.2.1-toc" class="bak">Ⓣ</a> <b class="erra">Ⓔ</b> <b class="rev1">①</b> <b class="anno">Ⓐ</b></h5>
<p class="sm-btm">
The
descriptions below use the following variables:</p>
<ul><li><p>
<dfn id="Input-RegExp"><i>Input</i></dfn>
is the String being matched by the regular expression pattern. The
notation <i>input</i>[<i>n</i>]
means the <i>n</i><sup><i>th</i></sup>
character of <i>input</i>,
where <i>n</i> can range
between 0 (inclusive) and <i>InputLength</i>
(exclusive).</p>
</li>
<li><p>
<dfn id="InputLength"><i>InputLength</i></dfn>
is the number of characters in the <i>Input</i>
String.</p>
</li>
<li><p>
<dfn id="NcapturingParens"><i>NcapturingParens</i></dfn>
is the total number of left capturing parentheses (i.e. the total
number of times the <i>Atom</i>
<b>::</b> <code><b>(</b></code><b>
</b><i>Disjunction</i> <code><b>)</b></code>
production is expanded) in the pattern. A left capturing
parenthesis is any <code><b>(</b></code>
pattern character that is matched by the <code><b>(</b></code>
terminal of the <i>Atom</i>
<b>::</b> <code><b>(</b></code><b>
</b><i>Disjunction</i> <code><b>)</b></code>
production.</p>
</li>
<li><p>
<dfn id="IgnoreCase"><i>IgnoreCase</i></dfn>
is the setting of the RegExp object's <code><b>ignoreCase</b></code>
property.</p>
</li>
<li><p>
<dfn id="Multiline"><i>Multiline</i></dfn>
is the setting of the RegExp object’s <code><b>multiline</b></code>
property.</p>
</li></ul><p>
Furthermore,
the descriptions below use the following internal data structures:</p>
<ul><li><p>
A
<dfn id="CharSet"><i>CharSet</i></dfn> is a
mathematical set of characters.</p>
</li>
<li><p>
A
<dfn id="State"><i>State</i></dfn> is an
ordered pair (<i>endIndex</i>,
<i>captures</i>)
where <dfn id="endIndex"><i>endIndex</i></dfn> is
an integer and <dfn id="captures"><i>captures</i></dfn>
is an internal array of <i><a href="#NcapturingParens">NcapturingParens</a></i>
values. <i>States</i>
are used to represent partial match states in the regular
expression matching algorithms. The <i>endIndex</i>
is one plus the index of the last input character matched so far by
the pattern, while <i>captures</i>
holds the results of capturing parentheses. The <i>n</i><sup><i>th</i></sup>
element of <i>captures</i>
is either a String that represents the value obtained by the <i>n</i><sup><i>th</i></sup>
set of capturing parentheses or <b>undefined</b> if the <i>n</i><sup><i>th</i></sup>
set of capturing parentheses hasn’t been reached yet. Due to
backtracking, many <i>States</i>
may be in use at any time during the matching process.</p>
</li>
<li><p>
A
<dfn id="MatchResult"><i>MatchResult</i></dfn> is
either a <i><a href="#State">State</a></i> or
the special token <b>failure</b> that indicates that the match
failed.</p>
</li>
<li><p>
A
<dfn id="Continuation"><i>Continuation</i></dfn>
procedure is an internal closure (i.e. an internal procedure with
some arguments already bound to values) that takes one <i><a href="#State">State</a></i>
argument and returns a <i><a href="#MatchResult">MatchResult</a></i>
result. If an internal closure references variables bound in the
function that creates the closure, the closure uses the values that
these variables had at the time the closure was created. The
<i><a href="#Continuation">Continuation</a></i>
attempts to match the remaining portion (specified by the closure's
already-bound arguments) of the pattern against the input String,
starting at the intermediate state given by its <i><a href="#State">State</a></i>
argument. If the match succeeds, the <i><a href="#Continuation">Continuation</a></i>
returns the final <i><a href="#State">State</a></i>
that it reached; if the match fails, the <i><a href="#Continuation">Continuation</a></i>
returns <b>failure</b>.</p>
</li>
<li><p>
A
<dfn id="Matcher"><i>Matcher</i></dfn> procedure
is an internal closure that takes two arguments -- a <i><a href="#State">State</a></i>
and a <i><a href="#Continuation">Continuation</a></i>
-- and returns a <i><a href="#MatchResult">MatchResult</a></i>
result. A <i>Matcher</i>
attempts to match a middle subpattern (specified by the closure's
already-bound arguments) of the pattern against the input String,
starting at the intermediate state given by its <i><a href="#State">State</a></i>
argument. The <i><a href="#Continuation">Continuation</a></i>
argument should be a closure that matches the rest of the pattern.
After matching the subpattern of a pattern to obtain a new <i><a href="#State">State</a></i>,
the <i><a href="#Matcher">Matcher</a></i> then
calls <i><a href="#Continuation">Continuation</a></i>
on that new <i><a href="#State">State</a></i>
to test if the rest of the pattern can match as well. If it can,
the matcher returns the <i><a href="#State">State</a></i>
returned by <i><a href="#Continuation">Continuation</a></i>;
if not, the <i><a href="#Matcher">Matcher</a></i>
may try different choices at its choice points, repeatedly calling
<i><a href="#Continuation">Continuation</a></i>
until it either succeeds or all possibilities have been exhausted.</p>
</li>
<li><p>
An
<dfn id="AssertionTester"><i>AssertionTester</i></dfn>
procedure is an internal closure that takes a <i><a href="#State">State</a></i>
argument and returns a Boolean result. The assertion tester tests a
specific condition (specified by the closure's already-bound
arguments) against the current place in the input String and
returns <b>true</b> if the condition matched or <b>false</b> if
not.</p>
</li>
<li><p>
An
<dfn id="EscapeValue"><i>EscapeValue</i></dfn> is
either a character or an integer. An <i>EscapeValue</i>
is used to denote the interpretation of a <i>DecimalEscape</i>
escape sequence: a character <i>ch</i>
means that the escape sequence is interpreted as the character <i>ch</i>,
while an integer <i>n</i>
means that the escape sequence is interpreted as a backreference to
the <i>n</i><sup>th</sup>
set of capturing parentheses.</p>
</li></ul><h5 id="x15.10.2.2">15.10.2.2 Pattern <a href="#x15.10.2.2">#</a> <a href="#x15.10.2.2-toc" class="bak">Ⓣ</a> <b class="erra">Ⓔ</b> <b class="rev1">①</b> <b class="anno">Ⓐ</b></h5>
<p>
The
production <i>Pattern</i><b>
:: </b><i>Disjunction</i><b>
</b>evaluates as follows:</p>
<ol><li><p>
Evaluate
<i>Disjunction</i> to obtain a <a href="#Matcher">Matcher</a> <i>m</i>.</p>
</li>
<li><p>
Return
an internal closure that takes two arguments, a String <i>str</i>
and an integer <i>index</i>, and performs the following:</p>
</li>
</ol><ol class="indent1"><li><p>
Let
<i><a href="#Input-RegExp">Input</a></i> be the given String <i>str</i>. This variable will be
used throughout the algorithms in <a href="#x15.10.2">15.10.2</a>.</p>
</li>
<li><p>
Let
<i><a href="#InputLength">InputLength</a></i> be the length of <i><a href="#Input-RegExp">Input</a></i>. This variable
will be used throughout the algorithms in <a href="#x15.10.2">15.10.2</a>.</p>
</li>
<li><p>
Let
<i>c</i> be a <a href="#Continuation">Continuation</a> that always returns its <a href="#State">State</a> argument
as a successful <a href="#MatchResult">MatchResult</a>.</p>
</li>
<li><p>
Let
<i>cap</i> be an internal array of <i><a href="#NcapturingParens">NcapturingParens</a></i>
<b>undefined</b> values, indexed 1 through <i><a href="#NcapturingParens">NcapturingParens</a></i>.</p>
</li>
<li><p>
Let
<i>x</i> be the <a href="#State">State</a> (<i>index</i>, <i>cap</i>).</p>
</li>
<li><p>
Call
<i>m</i>(<i>x</i>, <i>c</i>) and return its result.</p>
</li>
</ol><p><b class="note">NOTE</b> A
Pattern evaluates ("compiles") to an internal procedure
value. <code><b><a href="#x15.10.6.2">RegExp.prototype.exec</a></b></code>
can then apply this procedure to a String and an offset within the
String to determine whether the pattern would match starting at
exactly that offset within the String, and, if it does match, what
the values of the capturing parentheses would be. The algorithms in
<a href="#x15.10.2">15.10.2</a> are designed so that compiling a pattern may throw a
<b><a href="x15.11.html#x15.11.6.4" class="term-ref">SyntaxError</a></b> exception; on the other hand, once the pattern is
successfully compiled, applying its result internal procedure to
find a match in a String cannot throw an exception (except for any
host-defined exceptions that can occur anywhere such as
out-of-memory).</p>
<h5 id="x15.10.2.3">15.10.2.3 Disjunction <a href="#x15.10.2.3">#</a> <a href="#x15.10.2.3-toc" class="bak">Ⓣ</a> <b class="erra">Ⓔ</b> <b class="rev1">①</b> <b class="anno">Ⓐ</b></h5>
<p>
The
production <i>Disjunction</i>
<b>:: </b><i>Alternative</i>
evaluates by evaluating <i>Alternative</i>
to obtain a <i><a href="#Matcher">Matcher</a></i>
and returning that <i><a href="#Matcher">Matcher</a></i>.</p>
<p>
The
production <i>Disjunction</i>
<b>:: </b><i>Alternative</i>
<code><b>|</b></code> <i>Disjunction</i>
evaluates as follows:</p>
<ol><li><p>
Evaluate
<i>Alternative</i> to obtain a <a href="#Matcher">Matcher</a> <i>m1</i>.</p>
</li>
<li><p>
Evaluate
<i>Disjunction</i> to obtain a <a href="#Matcher">Matcher</a> <i>m2</i>.</p>
</li>
<li><p>
Return
an internal <a href="#Matcher">Matcher</a> closure that takes two arguments, a <a href="#State">State</a> <i>x</i>
and a <a href="#Continuation">Continuation</a> <i>c</i>, and performs the following:</p>
<ol><ol><ol><li><p>
Call
<i>m1</i>(<i>x</i>, <i>c</i>) and let <i>r</i> be its result.</p>
</li>
<li><p>
If
<i>r</i> isn't <b>failure</b>, return <i>r</i>.</p>
</li>
<li><p>
Call
<i>m2</i>(<i>x</i>, <i>c</i>) and return its result.</p>
</li></ol></ol></ol></li></ol><p>
</p><p><b class="note">NOTE</b> The
<code><b>|</b></code> regular
expression operator separates two alternatives. The pattern first
tries to match the left <i>Alternative</i>
(followed by the sequel of the regular expression); if it fails, it
tries to match the right <i>Disjunction</i>
(followed by the sequel of the regular expression). If the left
<i>Alternative</i>, the
right <i>Disjunction</i>,
and the sequel all have choice points, all choices in the sequel are
tried before moving on to the next choice in the left <i>Alternative</i>.
If choices in the left <i>Alternative</i>
are exhausted, the right <i>Disjunction</i>
is tried instead of the left <i>Alternative</i>.
Any capturing parentheses inside a portion of the pattern skipped by
<code><b>|</b></code> produce
<b>undefined</b> values instead of Strings. Thus, for example,</p>
<p class="code-example">
<code><b>/a|ab/.exec("abc")</b></code></p>
<p>returns
the result <code><b>"a"</b></code>
and not <code><b>"ab"</b></code>.
Moreover,</p>
<p class="code-example">
<code><b>/((a)|(ab))((c)|(bc))/.exec("abc")</b></code></p>
<p>returns
the array</p>
<p class="code-example">
<code><b>["abc",
"a", "a", undefined, "bc", undefined,
"bc"]</b></code></p>
<p>and
not</p>
<p class="code-example">
<code><b>["abc",
"ab", undefined, "ab", "c", "c",
undefined]</b></code></p>
<h5 id="x15.10.2.4">15.10.2.4 Alternative <a href="#x15.10.2.4">#</a> <a href="#x15.10.2.4-toc" class="bak">Ⓣ</a> <b class="erra">Ⓔ</b> <b class="rev1">①</b> <b class="anno">Ⓐ</b></h5>
<p>
The
production <i>Alternative</i>
<b>:: </b>[empty]
evaluates by returning a <a href="#Matcher">Matcher</a> that takes two arguments, a <a href="#State">State</a> <i>x</i>
and a <a href="#Continuation">Continuation</a> <i>c</i>,
and returns the result of calling <i>c</i>(<i>x</i>).</p>
<p>
The
production <i>Alternative</i>
<b>:: </b><i>Alternative</i>
<i>Term</i> evaluates as
follows:</p>
<ol><li><p>
Evaluate
<i>Alternative</i> to obtain a <a href="#Matcher">Matcher</a> <i>m1</i>.</p>
</li>
<li><p>
Evaluate
<i>Term</i> to obtain a <a href="#Matcher">Matcher</a> <i>m2</i>.</p>
</li>
<li><p>
Return
an internal <a href="#Matcher">Matcher</a> closure that takes two arguments, a <a href="#State">State</a> <i>x</i>
and a <a href="#Continuation">Continuation</a> <i>c</i>, and performs the following:</p>
<ol><ol><ol><li><p>
Create
a <a href="#Continuation">Continuation</a> <i>d</i> that takes a <a href="#State">State</a> argument <i>y</i> and
returns the result of calling <i>m2</i>(<i>y</i>, <i>c</i>).</p>
</li>
<li><p>
Call
<i>m1</i>(<i>x</i>, <i>d</i>) and return its result.</p>
</li></ol></ol></ol></li></ol><p><b class="note">NOTE</b> Consecutive
<i>Terms</i> try to
simultaneously match consecutive portions of the input String. If
the left <i>Alternative</i>,
the right <i>Term</i>,
and the sequel of the regular expression all have choice points, all
choices in the sequel are tried before moving on to the next choice
in the right <i>Term</i>,
and all choices in the right <i>Term</i>
are tried before moving on to the next choice in the left
<i>Alternative</i>.</p>
<h5 id="x15.10.2.5">15.10.2.5 Term <a href="#x15.10.2.5">#</a> <a href="#x15.10.2.5-toc" class="bak">Ⓣ</a> <b class="erra">Ⓔ</b> <b class="rev1">①</b> <b class="anno">Ⓐ</b></h5>
<p>
The
production <i>Term</i> <b>::
</b><i>Assertion</i>
evaluates by returning an internal <a href="#Matcher">Matcher</a> closure that takes two
arguments, a <a href="#State">State</a> <i>x</i>
and a <a href="#Continuation">Continuation</a> <i>c</i>,
and performs the following:</p>
<ol><li><p>
Evaluate
<i>Assertion</i> to obtain an <a href="#AssertionTester">AssertionTester</a> <i>t</i>.</p>
</li>
<li><p>
Call
<i>t</i>(<i>x</i>) and let <i>r</i> be the resulting Boolean value.</p>
</li>
<li><p>
If
<i>r</i> is <b>false</b>, return <b>failure</b>.</p>
</li>
<li><p>
Call
<i>c</i>(<i>x</i>) and return its result.</p>
</li></ol><p>
The
production <i>Term</i> <b>::
</b><i>Atom</i> evaluates
by evaluating <i>Atom</i>
to obtain a <a href="#Matcher">Matcher</a> and returning that <a href="#Matcher">Matcher</a>.</p>
<p>
The
production <i>Term</i> <b>::
</b><i>Atom</i>
<i>Quantifier</i>
evaluates as follows:</p>
<ol><li><p>
Evaluate
<i>Atom</i> to obtain a <a href="#Matcher">Matcher</a> <i>m</i>.</p>
</li>
<li><p>
Evaluate
<i>Quantifier</i> to obtain the three results: an integer <i>min</i>,
an integer (or <span class="symbol">∞</span>) <i>max</i>,
and Boolean <i>greedy</i>.</p>
</li>
<li><p>
If
<i>max</i> is finite and less than <i>min</i>, then throw a
<b><a href="x15.11.html#x15.11.6.4" class="term-ref">SyntaxError</a></b> exception.</p>
</li>
<li><p>
Let
<i>parenIndex</i> be the number of left capturing parentheses in
the entire regular expression that occur to the left of this
production expansion's <i>Term</i>. This is the total number of
times the <i>Atom</i> :: <code><b>(</b></code><b>
</b><i>Disjunction</i> <code><b>)</b></code>
production is expanded prior to this production's <i>Term</i> plus
the total number of <i>Atom</i> :: <code><b>(</b></code><b>
</b><i>Disjunction</i> <code><b>)</b></code>
productions enclosing this <i>Term</i>.</p>
</li>
<li><p>
Let
<i>parenCount</i> be the number of left capturing parentheses in
the expansion of this production's <i>Atom</i>. This is the total
number of <i>Atom</i> :: <code><b>(</b></code><b>
</b><i>Disjunction</i> <code><b>)</b></code>
productions enclosed by this production's <i>Atom</i>.</p>
</li>
<li><p>
Return
an internal <a href="#Matcher">Matcher</a> closure that takes two arguments, a <a href="#State">State</a> <i>x</i>
and a <a href="#Continuation">Continuation</a> <i>c</i>, and performs the following:</p>
<ol><ol><ol><li><p>
Call
<a href="#RepeatMatcher">RepeatMatcher</a>(<i>m</i>, <i>min</i>, <i>max</i>, <i>greedy</i>,
<i>x</i>, <i>c</i>, <i>parenIndex</i>, <i>parenCount</i>) and
return its result.</p>
</li></ol></ol></ol></li></ol><p>
The
abstract operation <dfn id="RepeatMatcher"><i>RepeatMatcher</i></dfn> takes eight parameters, a
<a href="#Matcher">Matcher</a> <i>m</i>, an
integer <i>min</i>, an
integer (or <span class="symbol">∞</span>) <i>max</i>,
a Boolean <i>greedy</i>,
a <a href="#State">State</a> <i>x</i>, a
<a href="#Continuation">Continuation</a> <i>c</i>, an
integer <i>parenIndex</i>,
and an integer <i>parenCount</i>,
and performs the following:</p>
<ol><li><p>
If
<i>max</i> is zero, then call <i>c</i>(<i>x</i>) and return its
result.</p>
</li>
<li><p>
Create
an internal <a href="#Continuation">Continuation</a> closure <i>d</i> that takes one <a href="#State">State</a> argument <i>y</i> and performs the following:</p>
<ol><ol><ol><li><p>
If
<i>min</i> is zero and <i>y</i>'s <i><a href="#endIndex">endIndex</a></i> is equal to
<i>x</i>'s <i><a href="#endIndex">endIndex</a></i>, then return <b>failure</b>.</p>
</li>
<li><p>
If
<i>min</i> is zero then let <i>min2</i> be zero; otherwise let
<i>min2</i> be <i>min</i>–1.</p>
</li>
<li><p>
If
<i>max</i> is <span class="symbol">∞</span>, then let
<i>max2</i> be <span class="symbol">∞</span>; otherwise
let <i>max2</i> be <i>max</i>–1.</p>
</li>
<li><p>
Call
<a href="#RepeatMatcher">RepeatMatcher</a>(<i>m</i>, <i>min2</i>, <i>max2</i>, <i>greedy</i>,
<i>y</i>, <i>c</i>, <i>parenIndex</i>, <i>parenCount</i>) and
return its result.</p>
</li></ol></ol></ol></li>
<li><p>
Let
<i>cap</i> be a fresh copy of <i>x</i>'s <i><a href="#captures">captures</a></i> internal
array.</p>
</li>
<li><p>
For
every integer <i>k</i> that satisfies <i>parenIndex</i> < <i>k</i>
and <i>k</i> <span class="symbol">≤</span>
<i>parenIndex</i>+<i>parenCount</i>, set <i>cap</i>[<i>k</i>] to
<b>undefined</b>.</p>
</li>
<li><p>
Let
<i>e</i> be <i>x</i>'s <i><a href="#endIndex">endIndex</a></i>.</p>
</li>
<li><p>
Let
<i>xr</i> be the <a href="#State">State</a> (<i>e</i>, <i>cap</i>).</p>
</li>
<li><p>
If
<i>min</i> is not zero, then call <i>m</i>(<i>xr</i>, <i>d</i>) and
return its result.</p>
</li>
<li><p>
If
<i>greedy</i> is <b>false</b>, then</p>
<ol><li><p>
Call
<i>c</i>(<i>x</i>) and let <i>z</i> be its result.</p>
</li>
<li><p>
If
<i>z</i> is not <b>failure</b>, return <i>z</i>.</p>
</li>
<li><p>
Call
<i>m</i>(<i>xr</i>, <i>d</i>) and return its result.</p>
</li></ol></li>
<li><p>
Call
<i>m</i>(<i>xr</i>, <i>d</i>) and let <i>z</i> be its result.</p>
</li>
<li><p>
If
<i>z</i> is not <b>failure</b>, return <i>z</i>.</p>
</li>
<li><p>
Call
<i>c</i>(<i>x</i>) and return its result.</p>
</li></ol><p><b class="note">NOTE</b> An
<i>Atom</i> followed by a
<i>Quantifier</i> is
repeated the number of times specified by the <i>Quantifier</i>.
A <i>Quantifier</i> can
be non-greedy, in which case the <i>Atom</i>
pattern is repeated as few times as possible while still matching
the sequel, or it can be greedy, in which case the <i>Atom</i>
pattern is repeated as many times as possible while still matching
the sequel. The <i>Atom</i>
pattern is repeated rather than the input String that it matches, so
different repetitions of the <i>Atom</i>
can match different input substrings.</p>
<p class="sp"><b class="note">NOTE 2</b> If the <i>Atom</i> and
the sequel of the regular expression all have choice points, the
<i>Atom</i> is first
matched as many (or as few, if non-greedy) times as possible. All
choices in the sequel are tried before moving on to the next choice
in the last repetition of <i>Atom</i>.
All choices in the last (n<sup>th</sup>) repetition of <i>Atom</i>
are tried before moving on to the next choice in the next-to-last
(n–1)<sup>st</sup> repetition of <i>Atom</i>;
at which point it may turn out that more or fewer repetitions of
<i>Atom</i> are now
possible; these are exhausted (again, starting with either as few or
as many as possible) before moving on to the next choice in the
(n-1)<sup>st</sup> repetition of <i>Atom</i>
and so on.</p>
<p>Compare</p>
<p class="code-example">
<code><b>/a[a-z]{2,4}/.exec("abcdefghi")</b></code></p>
<p>which
returns <code><b>"abcde"</b></code>
with</p>
<p class="code-example">
<code><b>/a[a-z]{2,4}?/.exec("abcdefghi")</b></code></p>
<p class="sp">which
returns <code><b>"abc"</b></code>.</p>
<p>Consider
also</p>
<p class="code-example">
<code><b>/(aa|aabaac|ba|b|c)*/.exec("aabaac")</b></code></p>
<p>which,
by the choice point ordering above, returns the array</p>
<p class="code-example">
<code><b>["aaba",
"ba"]</b></code></p>
<p>and
not any of:</p>
<p class="code-example">
<code><b>["aabaac",
"aabaac"]</b></code></p>
<p class="code-example">
<code><b>["aabaac",
"c"]</b></code></p>
<p>The
above ordering of choice points can be used to write a regular
expression that calculates the greatest common divisor of two
numbers (represented in unary notation). The following example
calculates the gcd of 10 and 15:</p>
<p class="code-example">
<code><b>"aaaaaaaaaa,aaaaaaaaaaaaaaa".replace(/^(a+)\1*,\1+$/,"$1")</b></code></p>
<p>
which
returns the gcd in unary notation <code><b>"aaaaa"</b></code>.</p>
<p><b class="note">NOTE 3</b> Step 4 of the <a href="#RepeatMatcher">RepeatMatcher</a> clears <i>Atom's</i>
<a href="#captures">captures</a> each time <i>Atom</i>
is repeated. We can see its behaviour in the regular expression</p>
<p class="code-example">
<code><b>/(z)((a+)?(b+)?(c))*/.exec("zaacbbbcac")</b></code></p>
<p>which
returns the array</p>
<p class="code-example">
<code><b>["zaacbbbcac",
"z", "ac", "a", undefined, "c"]</b></code></p>
<p>and
not</p>
<p class="code-example">
<code><b>["zaacbbbcac",
"z", "ac", "a", "bbb", "c"]</b></code></p>
<p>
because
each iteration of the outermost <code><b>*</b></code>
clears all captured Strings contained in the quantified <i>Atom</i>,
which in this case includes capture Strings numbered 2, 3, and 4.</p>
<p><b class="note">NOTE 4</b> Step 1 of the <a href="#RepeatMatcher">RepeatMatcher</a>'s <i>d</i>
closure states that, once the minimum number of repetitions has been
satisfied, any more expansions of <i>Atom</i>
that match the empty String are not considered for further
repetitions. This prevents the regular expression engine from
falling into an infinite loop on patterns such as:</p>
<p class="code-example">
<code><b>/(a*)*/.exec("b")</b></code></p>
<p>or
the slightly more complicated:</p>
<p class="code-example">
<code><b>/(a*)b\1+/.exec("baaaac")</b></code></p>
<p>which
returns the array</p>
<p class="code-example">
<code><b>["b",
""]</b></code></p>
<h5 id="x15.10.2.6">15.10.2.6 Assertion <a href="#x15.10.2.6">#</a> <a href="#x15.10.2.6-toc" class="bak">Ⓣ</a> <b class="erra">Ⓔ</b> <b class="rev1">①</b> <b class="anno">Ⓐ</b></h5>
<p>
The
production <i>Assertion</i>
<b>:: </b><code><b>^</b></code>
evaluates by returning an internal <a href="#AssertionTester">AssertionTester</a> closure that
takes a <a href="#State">State</a> argument <i>x</i>
and performs the following:</p>
<ol><li><p>
Let
<i>e</i> be <i>x</i>'s <i><a href="#endIndex">endIndex</a></i>.</p>
</li>
<li><p>
If
<i>e</i> is zero, return <b>true</b>.</p>
</li>
<li><p>
If
<i><a href="#Multiline">Multiline</a></i> is <b>false</b>, return <b>false</b>.</p>
</li>
<li><p>
If
the character <i><a href="#Input-RegExp">Input</a></i>[<i>e</i>–1] is one of <i><a href="x7.html#LineTerminator">LineTerminator</a></i>,
return <b>true</b>.</p>
</li>
<li><p>
Return
<b>false</b>.</p>
</li></ol><p>
The
production <i>Assertion</i>
<b>:: </b><code><b>$</b></code>
evaluates by returning an internal <a href="#AssertionTester">AssertionTester</a> closure that
takes a <a href="#State">State</a> argument <i>x</i>
and performs the following:</p>
<ol><li><p>
Let
<i>e</i> be <i>x</i>'s <i><a href="#endIndex">endIndex</a></i>.</p>
</li>
<li><p>
If
<i>e</i> is equal to <i><a href="#InputLength">InputLength</a></i>, return <b>true</b>.</p>
</li>
<li><p>
If
<i>multiline</i> is <b>false</b>, return <b>false</b>.</p>
</li>
<li><p>
If
the character <i><a href="#Input-RegExp">Input</a></i>[<i>e</i>] is one of <i><a href="x7.html#LineTerminator">LineTerminator</a></i>,
return <b>true</b>.</p>
</li>
<li><p>
Return
<b>false</b>.</p>
</li></ol><p>
The
production <i>Assertion</i>
<b>:: </b><code><b>\ b</b></code>
evaluates by returning an internal <a href="#AssertionTester">AssertionTester</a> closure that
takes a <a href="#State">State</a> argument <i>x</i>
and performs the following:</p>
<ol><li><p>
Let
<i>e</i> be <i>x</i>'s <i><a href="#endIndex">endIndex</a></i>.</p>
</li>
<li><p>
Call
<i><a href="#IsWordChar">IsWordChar</a></i>(<i>e</i>–1) and let <i>a</i> be the Boolean
result.</p>
</li>
<li><p>
Call
<i><a href="#IsWordChar">IsWordChar</a></i>(<i>e</i>) and let <i>b</i> be the Boolean result.</p>
</li>
<li><p>
If
<i>a</i> is <b>true</b> and <i>b</i> is <b>false</b>, return <b>true</b>.</p>
</li>
<li><p>
If
<i>a</i> is <b>false</b> and <i>b</i> is <b>true</b>, return <b>true</b>.</p>
</li>
<li><p>
Return
<b>false</b>.</p>
</li></ol><p>
The
production <i>Assertion</i>
<b>:: </b><code><b>\ B</b></code>
evaluates by returning an internal <a href="#AssertionTester">AssertionTester</a> closure that
takes a <a href="#State">State</a> argument <i>x</i>
and performs the following:</p>
<ol><li><p>
Let
<i>e</i> be <i>x</i>'s <i><a href="#endIndex">endIndex</a></i>.</p>
</li>
<li><p>
Call
<i><a href="#IsWordChar">IsWordChar</a></i>(<i>e</i>–1) and let <i>a</i> be the Boolean
result.</p>
</li>
<li><p>
Call
<i><a href="#IsWordChar">IsWordChar</a></i>(<i>e</i>) and let b be the Boolean result.</p>
</li>
<li><p>
If
a is <b>true</b> and b is <b>false</b>, return <b>false</b>.</p>
</li>
<li><p>
If
a is <b>false</b> and b is <b>true</b>, return <b>false</b>.</p>
</li>
<li><p>
Return
<b>true</b>.</p>
</li></ol><p>
The
production <i>Assertion</i>
<b>:: </b><code><b>( ? =</b></code> <i>Disjunction</i><code><b>
)</b></code> evaluates as follows:</p>
<ol><li><p>
Evaluate
<i>Disjunction</i> to obtain a <a href="#Matcher">Matcher</a> <i>m</i>.</p>
</li>
<li><p>
Return
an internal <a href="#Matcher">Matcher</a> closure that takes two arguments, a <a href="#State">State</a> <i>x</i>
and a <a href="#Continuation">Continuation</a> <i>c</i>, and performs the following steps:</p>
<ol><ol><ol><li><p>
Let
<i>d</i> be a <a href="#Continuation">Continuation</a> that always returns its <a href="#State">State</a> argument as a successful <a href="#MatchResult">MatchResult</a>.</p>
</li>
<li><p>
Call
<i>m</i>(<i>x</i>, <i>d</i>) and let <i>r</i> be its result.</p>
</li>
<li><p>
If
<i>r</i> is <b>failure</b>, return <b>failure</b>.</p>
</li>
<li><p>
Let
<i>y</i> be <i>r</i>'s State.</p>
</li>
<li><p>
Let
<i>cap</i> be <i>y</i>'s <i><a href="#captures">captures</a></i> internal array.</p>
</li>
<li><p>
Let
<i>xe</i> be <i>x</i>'s <i><a href="#endIndex">endIndex</a></i>.</p>
</li>
<li><p>
Let
<i>z</i> be the <a href="#State">State</a> (<i>xe</i>, <i>cap</i>).</p>
</li>
<li><p>
Call
<i>c</i>(<i>z</i>) and return its result.</p>
</li></ol></ol></ol></li></ol><p>
The
production <i>Assertion </i><b>::
</b><code><b>( ? !</b></code> <i>Disjunction</i><code><b>
)</b></code> evaluates as follows:</p>
<ol><li><p>
Evaluate
<i>Disjunction</i> to obtain a <a href="#Matcher">Matcher</a> <i>m</i>.</p>
</li>
<li><p>
Return
an internal <a href="#Matcher">Matcher</a> closure that takes two arguments, a <a href="#State">State</a> <i>x</i>
and a <a href="#Continuation">Continuation</a> <i>c</i>, and performs the following steps:</p>
<ol><ol><ol><li><p>
Let
<i>d</i> be a <a href="#Continuation">Continuation</a> that always returns its <a href="#State">State</a> argument as a successful <a href="#MatchResult">MatchResult</a>.</p>
</li>
<li><p>
Call
<i>m</i>(<i>x</i>, <i>d</i>) and let <i>r</i> be its result.</p>
</li>
<li><p>
If
<i>r</i> isn't <b>failure</b>, return <b>failure</b>.</p>
</li>
<li><p>
Call
<i>c</i>(<i>x</i>) and return its result.</p>
</li></ol></ol></ol></li></ol><p>
The
abstract operation <dfn id="IsWordChar"><i>IsWordChar</i></dfn>
takes an integer parameter <i>e</i>
and performs the following:</p>
<ol><li><p>
If
<i>e</i> == –1 or <i>e</i> == <i><a href="#InputLength">InputLength</a></i>, return <b>false</b>.</p>
</li>
<li><p>
Let
<i>c</i> be the character <i><a href="#Input-RegExp">Input</a></i>[<i>e</i>].</p>
</li>
<li><p>
If
<i>c</i> is one of the sixty-three characters below, return <b>true</b>.</p>
<table width="582" border="0" cellpadding="0" cellspacing="0"><colgroup><col width="22"><col width="22"><col width="22"><col width="22"><col width="22"><col width="22"><col width="22"><col width="22"><col width="22"><col width="22"><col width="22"><col width="22"><col width="22"><col width="22"><col width="22"><col width="22"><col width="22"><col width="22"><col width="22"><col width="22"><col width="22"><col width="22"><col width="22"><col width="22"><col width="22"><col width="22"></colgroup><thead><tr valign="TOP"><td width="22">
<p><code><b>a</b></code></p>
</td>
<td width="22">
<p><code><b>b</b></code></p>
</td>
<td width="22">
<p><code><b>c</b></code></p>
</td>