-
Notifications
You must be signed in to change notification settings - Fork 5.6k
/
Pattern.java
5946 lines (5642 loc) · 221 KB
/
Pattern.java
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
/*
* Copyright (c) 1999, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.util.regex;
import java.text.Normalizer;
import java.text.Normalizer.Form;
import java.util.Locale;
import java.util.Iterator;
import java.util.Map;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
import java.util.Arrays;
import java.util.NoSuchElementException;
import java.util.Spliterator;
import java.util.Spliterators;
import java.util.function.Predicate;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;
import jdk.internal.util.ArraysSupport;
/**
* A compiled representation of a regular expression.
*
* <p> A regular expression, specified as a string, must first be compiled into
* an instance of this class. The resulting pattern can then be used to create
* a {@link Matcher} object that can match arbitrary {@linkplain
* java.lang.CharSequence character sequences} against the regular
* expression. All of the state involved in performing a match resides in the
* matcher, so many matchers can share the same pattern.
*
* <p> A typical invocation sequence is thus
*
* <blockquote><pre>
* Pattern p = Pattern.{@link #compile compile}("a*b");
* Matcher m = p.{@link #matcher matcher}("aaaaab");
* boolean b = m.{@link Matcher#matches matches}();</pre></blockquote>
*
* <p> A {@link #matches matches} method is defined by this class as a
* convenience for when a regular expression is used just once. This method
* compiles an expression and matches an input sequence against it in a single
* invocation. The statement
*
* <blockquote><pre>
* boolean b = Pattern.matches("a*b", "aaaaab");</pre></blockquote>
*
* is equivalent to the three statements above, though for repeated matches it
* is less efficient since it does not allow the compiled pattern to be reused.
*
* <p> Instances of this class are immutable and are safe for use by multiple
* concurrent threads. Instances of the {@link Matcher} class are not safe for
* such use.
*
*
* <h2><a id="sum">Summary of regular-expression constructs</a></h2>
*
* <table class="borderless">
* <caption style="display:none">Regular expression constructs, and what they match</caption>
* <thead style="text-align:left">
* <tr>
* <th id="construct">Construct</th>
* <th id="matches">Matches</th>
* </tr>
* </thead>
* <tbody style="text-align:left">
*
* <tr><th colspan="2" style="padding-top:20px" id="characters">Characters</th></tr>
*
* <tr><th style="vertical-align:top; font-weight: normal" id="x"><i>x</i></th>
* <td headers="matches characters x">The character <i>x</i></td></tr>
* <tr><th style="vertical-align:top; font-weight: normal" id="backslash">{@code \\}</th>
* <td headers="matches characters backslash">The backslash character</td></tr>
* <tr><th style="vertical-align:top; font-weight: normal" id="octal_n">{@code \0}<i>n</i></th>
* <td headers="matches characters octal_n">The character with octal value {@code 0}<i>n</i>
* (0 {@code <=} <i>n</i> {@code <=} 7)</td></tr>
* <tr><th style="vertical-align:top; font-weight: normal" id="octal_nn">{@code \0}<i>nn</i></th>
* <td headers="matches characters octal_nn">The character with octal value {@code 0}<i>nn</i>
* (0 {@code <=} <i>n</i> {@code <=} 7)</td></tr>
* <tr><th style="vertical-align:top; font-weight: normal" id="octal_nnn">{@code \0}<i>mnn</i></th>
* <td headers="matches characters octal_nnn">The character with octal value {@code 0}<i>mnn</i>
* (0 {@code <=} <i>m</i> {@code <=} 3,
* 0 {@code <=} <i>n</i> {@code <=} 7)</td></tr>
* <tr><th style="vertical-align:top; font-weight: normal" id="hex_hh">{@code \x}<i>hh</i></th>
* <td headers="matches characters hex_hh">The character with hexadecimal value {@code 0x}<i>hh</i></td></tr>
* <tr><th style="vertical-align:top; font-weight: normal" id="hex_hhhh"><code>\u</code><i>hhhh</i></th>
* <td headers="matches characters hex_hhhh">The character with hexadecimal value {@code 0x}<i>hhhh</i></td></tr>
* <tr><th style="vertical-align:top; font-weight: normal" id="hex_h_h"><code>\x</code><i>{h...h}</i></th>
* <td headers="matches characters hex_h_h">The character with hexadecimal value {@code 0x}<i>h...h</i>
* ({@link java.lang.Character#MIN_CODE_POINT Character.MIN_CODE_POINT}
* <= {@code 0x}<i>h...h</i> <=
* {@link java.lang.Character#MAX_CODE_POINT Character.MAX_CODE_POINT})</td></tr>
* <tr><th style="vertical-align:top; font-weight: normal" id="unicode_name"><code>\N{</code><i>name</i><code>}</code></th>
* <td headers="matches characters unicode_name">The character with Unicode character name <i>'name'</i></td></tr>
* <tr><th style="vertical-align:top; font-weight:normal" id="tab">{@code \t}</th>
* <td headers="matches characters tab">The tab character (<code>'\u0009'</code>)</td></tr>
* <tr><th style="vertical-align:top; font-weight:normal" id="newline">{@code \n}</th>
* <td headers="matches characters newline">The newline (line feed) character (<code>'\u000A'</code>)</td></tr>
* <tr><th style="vertical-align:top; font-weight:normal" id="return">{@code \r}</th>
* <td headers="matches characters return">The carriage-return character (<code>'\u000D'</code>)</td></tr>
* <tr><th style="vertical-align:top; font-weight:normal" id="form_feed">{@code \f}</th>
* <td headers="matches characters form_feed">The form-feed character (<code>'\u000C'</code>)</td></tr>
* <tr><th style="vertical-align:top; font-weight:normal" id="bell">{@code \a}</th>
* <td headers="matches characters bell">The alert (bell) character (<code>'\u0007'</code>)</td></tr>
* <tr><th style="vertical-align:top; font-weight:normal" id="escape">{@code \e}</th>
* <td headers="matches characters escape">The escape character (<code>'\u001B'</code>)</td></tr>
* <tr><th style="vertical-align:top; font-weight:normal" id="ctrl_x">{@code \c}<i>x</i></th>
* <td headers="matches characters ctrl_x">The control character corresponding to <i>x</i></td></tr>
*
* <tr><th colspan="2" style="padding-top:20px" id="classes">Character classes</th></tr>
*
* <tr><th style="vertical-align:top; font-weight:normal" id="simple">{@code [abc]}</th>
* <td headers="matches classes simple">{@code a}, {@code b}, or {@code c} (simple class)</td></tr>
* <tr><th style="vertical-align:top; font-weight:normal" id="negation">{@code [^abc]}</th>
* <td headers="matches classes negation">Any character except {@code a}, {@code b}, or {@code c} (negation)</td></tr>
* <tr><th style="vertical-align:top; font-weight:normal" id="range">{@code [a-zA-Z]}</th>
* <td headers="matches classes range">{@code a} through {@code z}
* or {@code A} through {@code Z}, inclusive (range)</td></tr>
* <tr><th style="vertical-align:top; font-weight:normal" id="union">{@code [a-d[m-p]]}</th>
* <td headers="matches classes union">{@code a} through {@code d},
* or {@code m} through {@code p}: {@code [a-dm-p]} (union)</td></tr>
* <tr><th style="vertical-align:top; font-weight:normal" id="intersection">{@code [a-z&&[def]]}</th>
* <td headers="matches classes intersection">{@code d}, {@code e}, or {@code f} (intersection)</tr>
* <tr><th style="vertical-align:top; font-weight:normal" id="subtraction1">{@code [a-z&&[^bc]]}</th>
* <td headers="matches classes subtraction1">{@code a} through {@code z},
* except for {@code b} and {@code c}: {@code [ad-z]} (subtraction)</td></tr>
* <tr><th style="vertical-align:top; font-weight:normal" id="subtraction2">{@code [a-z&&[^m-p]]}</th>
* <td headers="matches classes subtraction2">{@code a} through {@code z},
* and not {@code m} through {@code p}: {@code [a-lq-z]}(subtraction)</td></tr>
*
* <tr><th colspan="2" style="padding-top:20px" id="predef">Predefined character classes</th></tr>
*
* <tr><th style="vertical-align:top; font-weight:normal" id="any">{@code .}</th>
* <td headers="matches predef any">Any character (may or may not match <a href="#lt">line terminators</a>)</td></tr>
* <tr><th style="vertical-align:top; font-weight:normal" id="digit">{@code \d}</th>
* <td headers="matches predef digit">A digit: {@code [0-9]}</td></tr>
* <tr><th style="vertical-align:top; font-weight:normal" id="non_digit">{@code \D}</th>
* <td headers="matches predef non_digit">A non-digit: {@code [^0-9]}</td></tr>
* <tr><th style="vertical-align:top; font-weight:normal" id="horiz_white">{@code \h}</th>
* <td headers="matches predef horiz_white">A horizontal whitespace character:
* <code>[ \t\xA0\u1680\u180e\u2000-\u200a\u202f\u205f\u3000]</code></td></tr>
* <tr><th style="vertical-align:top; font-weight:normal" id="non_horiz_white">{@code \H}</th>
* <td headers="matches predef non_horiz_white">A non-horizontal whitespace character: {@code [^\h]}</td></tr>
* <tr><th style="vertical-align:top; font-weight:normal" id="white">{@code \s}</th>
* <td headers="matches predef white">A whitespace character: {@code [ \t\n\x0B\f\r]}</td></tr>
* <tr><th style="vertical-align:top; font-weight:normal" id="non_white">{@code \S}</th>
* <td headers="matches predef non_white">A non-whitespace character: {@code [^\s]}</td></tr>
* <tr><th style="vertical-align:top; font-weight:normal" id="vert_white">{@code \v}</th>
* <td headers="matches predef vert_white">A vertical whitespace character: <code>[\n\x0B\f\r\x85\u2028\u2029]</code>
* </td></tr>
* <tr><th style="vertical-align:top; font-weight:normal" id="non_vert_white">{@code \V}</th>
* <td headers="matches predef non_vert_white">A non-vertical whitespace character: {@code [^\v]}</td></tr>
* <tr><th style="vertical-align:top; font-weight:normal" id="word">{@code \w}</th>
* <td headers="matches predef word">A word character: {@code [a-zA-Z_0-9]}</td></tr>
* <tr><th style="vertical-align:top; font-weight:normal" id="non_word">{@code \W}</th>
* <td headers="matches predef non_word">A non-word character: {@code [^\w]}</td></tr>
*
* <tr><th colspan="2" style="padding-top:20px" id="posix"><b>POSIX character classes (US-ASCII only)</b></th></tr>
*
* <tr><th style="vertical-align:top; font-weight:normal" id="Lower">{@code \p{Lower}}</th>
* <td headers="matches posix Lower">A lower-case alphabetic character: {@code [a-z]}</td></tr>
* <tr><th style="vertical-align:top; font-weight:normal" id="Upper">{@code \p{Upper}}</th>
* <td headers="matches posix Upper">An upper-case alphabetic character:{@code [A-Z]}</td></tr>
* <tr><th style="vertical-align:top; font-weight:normal" id="ASCII">{@code \p{ASCII}}</th>
* <td headers="matches posix ASCII">All ASCII:{@code [\x00-\x7F]}</td></tr>
* <tr><th style="vertical-align:top; font-weight:normal" id="Alpha">{@code \p{Alpha}}</th>
* <td headers="matches posix Alpha">An alphabetic character:{@code [\p{Lower}\p{Upper}]}</td></tr>
* <tr><th style="vertical-align:top; font-weight:normal" id="Digit">{@code \p{Digit}}</th>
* <td headers="matches posix Digit">A decimal digit: {@code [0-9]}</td></tr>
* <tr><th style="vertical-align:top; font-weight:normal" id="Alnum">{@code \p{Alnum}}</th>
* <td headers="matches posix Alnum">An alphanumeric character:{@code [\p{Alpha}\p{Digit}]}</td></tr>
* <tr><th style="vertical-align:top; font-weight:normal" id="Punct">{@code \p{Punct}}</th>
* <td headers="matches posix Punct">Punctuation: One of {@code !"#$%&'()*+,-./:;<=>?@[\]^_`{|}~}</td></tr>
* <!-- {@code [\!"#\$%&'\(\)\*\+,\-\./:;\<=\>\?@\[\\\]\^_`\{\|\}~]}
* {@code [\X21-\X2F\X31-\X40\X5B-\X60\X7B-\X7E]} -->
* <tr><th style="vertical-align:top; font-weight:normal" id="Graph">{@code \p{Graph}}</th>
* <td headers="matches posix Graph">A visible character: {@code [\p{Alnum}\p{Punct}]}</td></tr>
* <tr><th style="vertical-align:top; font-weight:normal" id="Print">{@code \p{Print}}</th>
* <td headers="matches posix Print">A printable character: {@code [\p{Graph}\x20]}</td></tr>
* <tr><th style="vertical-align:top; font-weight:normal" id="Blank">{@code \p{Blank}}</th>
* <td headers="matches posix Blank">A space or a tab: {@code [ \t]}</td></tr>
* <tr><th style="vertical-align:top; font-weight:normal" id="Cntrl">{@code \p{Cntrl}}</th>
* <td headers="matches posix Cntrl">A control character: {@code [\x00-\x1F\x7F]}</td></tr>
* <tr><th style="vertical-align:top; font-weight:normal" id="XDigit">{@code \p{XDigit}}</th>
* <td headers="matches posix XDigit">A hexadecimal digit: {@code [0-9a-fA-F]}</td></tr>
* <tr><th style="vertical-align:top; font-weight:normal" id="Space">{@code \p{Space}}</th>
* <td headers="matches posix Space">A whitespace character: {@code [ \t\n\x0B\f\r]}</td></tr>
*
* <tr><th colspan="2" style="padding-top:20px" id="java">java.lang.Character classes (simple <a href="#jcc">java character type</a>)</th></tr>
*
* <tr><th style="vertical-align:top; font-weight:normal" id="javaLowerCase">{@code \p{javaLowerCase}}</th>
* <td headers="matches java javaLowerCase">Equivalent to java.lang.Character.isLowerCase()</td></tr>
* <tr><th style="vertical-align:top; font-weight:normal" id="javaUpperCase">{@code \p{javaUpperCase}}</th>
* <td headers="matches java javaUpperCase">Equivalent to java.lang.Character.isUpperCase()</td></tr>
* <tr><th style="vertical-align:top; font-weight:normal" id="javaWhitespace">{@code \p{javaWhitespace}}</th>
* <td headers="matches java javaWhitespace">Equivalent to java.lang.Character.isWhitespace()</td></tr>
* <tr><th style="vertical-align:top; font-weight:normal" id="javaMirrored">{@code \p{javaMirrored}}</th>
* <td headers="matches java javaMirrored">Equivalent to java.lang.Character.isMirrored()</td></tr>
*
* <tr><th colspan="2" style="padding-top:20px" id="unicode">Classes for Unicode scripts, blocks, categories and binary properties</th></tr>
*
* <tr><th style="vertical-align:top; font-weight:normal" id="IsLatin">{@code \p{IsLatin}}</th>
* <td headers="matches unicode IsLatin">A Latin script character (<a href="#usc">script</a>)</td></tr>
* <tr><th style="vertical-align:top; font-weight:normal" id="InGreek">{@code \p{InGreek}}</th>
* <td headers="matches unicode InGreek">A character in the Greek block (<a href="#ubc">block</a>)</td></tr>
* <tr><th style="vertical-align:top; font-weight:normal" id="Lu">{@code \p{Lu}}</th>
* <td headers="matches unicode Lu">An uppercase letter (<a href="#ucc">category</a>)</td></tr>
* <tr><th style="vertical-align:top; font-weight:normal" id="IsAlphabetic">{@code \p{IsAlphabetic}}</th>
* <td headers="matches unicode IsAlphabetic">An alphabetic character (<a href="#ubpc">binary property</a>)</td></tr>
* <tr><th style="vertical-align:top; font-weight:normal" id="Sc">{@code \p{Sc}}</th>
* <td headers="matches unicode Sc">A currency symbol</td></tr>
* <tr><th style="vertical-align:top; font-weight:normal" id="not_InGreek">{@code \P{InGreek}}</th>
* <td headers="matches unicode not_InGreek">Any character except one in the Greek block (negation)</td></tr>
* <tr><th style="vertical-align:top; font-weight:normal" id="not_uppercase">{@code [\p{L}&&[^\p{Lu}]]}</th>
* <td headers="matches unicode not_uppercase">Any letter except an uppercase letter (subtraction)</td></tr>
*
* <tr><th colspan="2" style="padding-top:20px" id="bounds">Boundary matchers</th></tr>
*
* <tr><th style="vertical-align:top; font-weight:normal" id="begin_line">{@code ^}</th>
* <td headers="matches bounds begin_line">The beginning of a line</td></tr>
* <tr><th style="vertical-align:top; font-weight:normal" id="end_line">{@code $}</th>
* <td headers="matches bounds end_line">The end of a line</td></tr>
* <tr><th style="vertical-align:top; font-weight:normal" id="word_boundary">{@code \b}</th>
* <td headers="matches bounds word_boundary">A word boundary</td></tr>
* <tr><th style="vertical-align:top; font-weight:normal" id="grapheme_cluster_boundary">{@code \b{g}}</th>
* <td headers="matches bounds grapheme_cluster_boundary">A Unicode extended grapheme cluster boundary</td></tr>
* <tr><th style="vertical-align:top; font-weight:normal" id="non_word_boundary">{@code \B}</th>
* <td headers="matches bounds non_word_boundary">A non-word boundary</td></tr>
* <tr><th style="vertical-align:top; font-weight:normal" id="begin_input">{@code \A}</th>
* <td headers="matches bounds begin_input">The beginning of the input</td></tr>
* <tr><th style="vertical-align:top; font-weight:normal" id="end_prev_match">{@code \G}</th>
* <td headers="matches bounds end_prev_match">The end of the previous match</td></tr>
* <tr><th style="vertical-align:top; font-weight:normal" id="end_input_except_term">{@code \Z}</th>
* <td headers="matches bounds end_input_except_term">The end of the input but for the final
* <a href="#lt">terminator</a>, if any</td></tr>
* <tr><th style="vertical-align:top; font-weight:normal" id="end_input">{@code \z}</th>
* <td headers="matches bounds end_input">The end of the input</td></tr>
*
* <tr><th colspan="2" style="padding-top:20px" id="linebreak">Linebreak matcher</th></tr>
*
* <tr><th style="vertical-align:top; font-weight:normal" id="any_unicode_linebreak">{@code \R}</th>
* <td headers="matches linebreak any_unicode_linebreak">Any Unicode linebreak sequence, is equivalent to
* <code>\u000D\u000A|[\u000A\u000B\u000C\u000D\u0085\u2028\u2029]
* </code></td></tr>
*
* <tr><th colspan="2" style="padding-top:20px" id="grapheme">Unicode Extended Grapheme matcher</th></tr>
*
* <tr><th style="vertical-align:top; font-weight:normal" id="grapheme_any">{@code \X}</th>
* <td headers="matches grapheme grapheme_any">Any Unicode extended grapheme cluster</td></tr>
*
* <tr><th colspan="2" style="padding-top:20px" id="greedy">Greedy quantifiers</th></tr>
*
* <tr><th style="vertical-align:top; font-weight:normal" id="greedy_once_or_not"><i>X</i>{@code ?}</th>
* <td headers="matches greedy greedy_once_or_not"><i>X</i>, once or not at all</td></tr>
* <tr><th style="vertical-align:top; font-weight:normal" id="greedy_zero_or_more"><i>X</i>{@code *}</th>
* <td headers="matches greedy greedy_zero_or_more"><i>X</i>, zero or more times</td></tr>
* <tr><th style="vertical-align:top; font-weight:normal" id="greedy_one_or_more"><i>X</i>{@code +}</th>
* <td headers="matches greedy greedy_one_or_more"><i>X</i>, one or more times</td></tr>
* <tr><th style="vertical-align:top; font-weight:normal" id="greedy_exactly"><i>X</i><code>{</code><i>n</i><code>}</code></th>
* <td headers="matches greedy greedy_exactly"><i>X</i>, exactly <i>n</i> times</td></tr>
* <tr><th style="vertical-align:top; font-weight:normal" id="greedy_at_least"><i>X</i><code>{</code><i>n</i>{@code ,}}</th>
* <td headers="matches greedy greedy_at_least"><i>X</i>, at least <i>n</i> times</td></tr>
* <tr><th style="vertical-align:top; font-weight:normal" id="greedy_at_least_up_to"><i>X</i><code>{</code><i>n</i>{@code ,}<i>m</i><code>}</code></th>
* <td headers="matches greedy greedy_at_least_up_to"><i>X</i>, at least <i>n</i> but not more than <i>m</i> times</td></tr>
*
* <tr><th colspan="2" style="padding-top:20px" id="reluc">Reluctant quantifiers</th></tr>
*
* <tr><th style="vertical-align:top; font-weight:normal" id="reluc_once_or_not"><i>X</i>{@code ??}</th>
* <td headers="matches reluc reluc_once_or_not"><i>X</i>, once or not at all</td></tr>
* <tr><th style="vertical-align:top; font-weight:normal" id="reluc_zero_or_more"><i>X</i>{@code *?}</th>
* <td headers="matches reluc reluc_zero_or_more"><i>X</i>, zero or more times</td></tr>
* <tr><th style="vertical-align:top; font-weight:normal" id="reluc_one_or_more"><i>X</i>{@code +?}</th>
* <td headers="matches reluc reluc_one_or_more"><i>X</i>, one or more times</td></tr>
* <tr><th style="vertical-align:top; font-weight:normal" id="reluc_exactly"><i>X</i><code>{</code><i>n</i><code>}?</code></th>
* <td headers="matches reluc reluc_exactly"><i>X</i>, exactly <i>n</i> times</td></tr>
* <tr><th style="vertical-align:top; font-weight:normal" id="reluc_at_least"><i>X</i><code>{</code><i>n</i><code>,}?</code></th>
* <td headers="matches reluc reluc_at_least"><i>X</i>, at least <i>n</i> times</td></tr>
* <tr><th style="vertical-align:top; font-weight:normal" id="reluc_at_least_up_to"><i>X</i><code>{</code><i>n</i>{@code ,}<i>m</i><code>}?</code></th>
* <td headers="matches reluc reluc_at_least_up_to"><i>X</i>, at least <i>n</i> but not more than <i>m</i> times</td></tr>
*
* <tr><th colspan="2" style="padding-top:20px" id="poss">Possessive quantifiers</th></tr>
*
* <tr><th style="vertical-align:top; font-weight:normal" id="poss_once_or_not"><i>X</i>{@code ?+}</th>
* <td headers="matches poss poss_once_or_not"><i>X</i>, once or not at all</td></tr>
* <tr><th style="vertical-align:top; font-weight:normal" id="poss_zero_or_more"><i>X</i>{@code *+}</th>
* <td headers="matches poss poss_zero_or_more"><i>X</i>, zero or more times</td></tr>
* <tr><th style="vertical-align:top; font-weight:normal" id="poss_one_or_more"><i>X</i>{@code ++}</th>
* <td headers="matches poss poss_one_or_more"><i>X</i>, one or more times</td></tr>
* <tr><th style="vertical-align:top; font-weight:normal" id="poss_exactly"><i>X</i><code>{</code><i>n</i><code>}+</code></th>
* <td headers="matches poss poss_exactly"><i>X</i>, exactly <i>n</i> times</td></tr>
* <tr><th style="vertical-align:top; font-weight:normal" id="poss_at_least"><i>X</i><code>{</code><i>n</i><code>,}+</code></th>
* <td headers="matches poss poss_at_least"><i>X</i>, at least <i>n</i> times</td></tr>
* <tr><th style="vertical-align:top; font-weight:normal" id="poss_at_least_up_to"><i>X</i><code>{</code><i>n</i>{@code ,}<i>m</i><code>}+</code></th>
* <td headers="matches poss poss_at_least_up_to"><i>X</i>, at least <i>n</i> but not more than <i>m</i> times</td></tr>
*
* <tr><th colspan="2" style="padding-top:20px" id="logical">Logical operators</th></tr>
*
* <tr><th style="vertical-align:top; font-weight:normal" id="concat"><i>XY</i></th>
* <td headers="matches logical concat"><i>X</i> followed by <i>Y</i></td></tr>
* <tr><th style="vertical-align:top; font-weight:normal" id="alternate"><i>X</i>{@code |}<i>Y</i></th>
* <td headers="matches logical alternate">Either <i>X</i> or <i>Y</i></td></tr>
* <tr><th style="vertical-align:top; font-weight:normal" id="group">{@code (}<i>X</i>{@code )}</th>
* <td headers="matches logical group">X, as a <a href="#cg">capturing group</a></td></tr>
*
* <tr><th colspan="2" style="padding-top:20px" id="backref">Back references</th></tr>
*
* <tr><th style="vertical-align:top; font-weight:normal" id="back_nth">{@code \}<i>n</i></th>
* <td headers="matches backref back_nth">Whatever the <i>n</i><sup>th</sup>
* <a href="#cg">capturing group</a> matched</td></tr>
* <tr><th style="vertical-align:top; font-weight:normal" id="back_named">{@code \}<i>k</i><<i>name</i>></th>
* <td headers="matches backref back_named">Whatever the
* <a href="#groupname">named-capturing group</a> "name" matched</td></tr>
*
* <tr><th colspan="2" style="padding-top:20px" id="quote">Quotation</th></tr>
*
* <tr><th style="vertical-align:top; font-weight:normal" id="quote_follow">{@code \}</th>
* <td headers="matches quote quote_follow">Nothing, but quotes the following character</td></tr>
* <tr><th style="vertical-align:top; font-weight:normal" id="quote_begin">{@code \Q}</th>
* <td headers="matches quote quote_begin">Nothing, but quotes all characters until {@code \E}</td></tr>
* <tr><th style="vertical-align:top; font-weight:normal" id="quote_end">{@code \E}</th>
* <td headers="matches quote quote_end">Nothing, but ends quoting started by {@code \Q}</td></tr>
* <!-- Metachars: !$()*+.<>?[\]^{|} -->
*
* <tr><th colspan="2" style="padding-top:20px" id="special">Special constructs (named-capturing and non-capturing)</th></tr>
*
* <tr><th style="vertical-align:top; font-weight:normal" id="named_group"><code>(?<<a href="#groupname">name</a>></code><i>X</i>{@code )}</th>
* <td headers="matches special named_group"><i>X</i>, as a named-capturing group</td></tr>
* <tr><th style="vertical-align:top; font-weight:normal" id="non_capture_group">{@code (?:}<i>X</i>{@code )}</th>
* <td headers="matches special non_capture_group"><i>X</i>, as a non-capturing group</td></tr>
* <tr><th style="vertical-align:top; font-weight:normal" id="flags"><code>(?idmsuxU-idmsuxU) </code></th>
* <td headers="matches special flags">Nothing, but turns match flags <a href="#CASE_INSENSITIVE">i</a>
* <a href="#UNIX_LINES">d</a> <a href="#MULTILINE">m</a> <a href="#DOTALL">s</a>
* <a href="#UNICODE_CASE">u</a> <a href="#COMMENTS">x</a> <a href="#UNICODE_CHARACTER_CLASS">U</a>
* on - off</td></tr>
* <tr><th style="vertical-align:top; font-weight:normal" id="non_capture_group_flags">{@code (?idmsuxU-idmsuxU:}<i>X</i>{@code )} </th>
* <td headers="matches special non_capture_group_flags"><i>X</i>, as a <a href="#cg">non-capturing group</a> with the
* given flags <a href="#CASE_INSENSITIVE">i</a> <a href="#UNIX_LINES">d</a>
* <a href="#MULTILINE">m</a> <a href="#DOTALL">s</a> <a href="#UNICODE_CASE">u</a >
* <a href="#COMMENTS">x</a> <a href="#UNICODE_CHARACTER_CLASS">U</a> on - off</td></tr>
* <tr><th style="vertical-align:top; font-weight:normal" id="pos_lookahead">{@code (?=}<i>X</i>{@code )}</th>
* <td headers="matches special pos_lookahead"><i>X</i>, via zero-width positive lookahead</td></tr>
* <tr><th style="vertical-align:top; font-weight:normal" id="neg_lookahead">{@code (?!}<i>X</i>{@code )}</th>
* <td headers="matches special neg_lookahead"><i>X</i>, via zero-width negative lookahead</td></tr>
* <tr><th style="vertical-align:top; font-weight:normal" id="pos_lookbehind">{@code (?<=}<i>X</i>{@code )}</th>
* <td headers="matches special pos_lookbehind"><i>X</i>, via zero-width positive lookbehind</td></tr>
* <tr><th style="vertical-align:top; font-weight:normal" id="neg_lookbehind">{@code (?<!}<i>X</i>{@code )}</th>
* <td headers="matches special neg_lookbehind"><i>X</i>, via zero-width negative lookbehind</td></tr>
* <tr><th style="vertical-align:top; font-weight:normal" id="indep_non_capture_group">{@code (?>}<i>X</i>{@code )}</th>
* <td headers="matches special indep_non_capture_group"><i>X</i>, as an independent, non-capturing group</td></tr>
*
* </tbody>
* </table>
*
* <hr>
*
*
* <h2><a id="bs">Backslashes, escapes, and quoting</a></h2>
*
* <p> The backslash character ({@code '\'}) serves to introduce escaped
* constructs, as defined in the table above, as well as to quote characters
* that otherwise would be interpreted as unescaped constructs. Thus the
* expression {@code \\} matches a single backslash and <code>\{</code> matches a
* left brace.
*
* <p> It is an error to use a backslash prior to any alphabetic character that
* does not denote an escaped construct; these are reserved for future
* extensions to the regular-expression language. A backslash may be used
* prior to a non-alphabetic character regardless of whether that character is
* part of an unescaped construct.
*
* <p> Backslashes within string literals in Java source code are interpreted
* as required by
* <cite>The Java Language Specification</cite>
* as either Unicode escapes (section {@jls 3.3}) or other character escapes (section {@jls 3.10.6}).
* It is therefore necessary to double backslashes in string
* literals that represent regular expressions to protect them from
* interpretation by the Java bytecode compiler. The string literal
* <code>"\b"</code>, for example, matches a single backspace character when
* interpreted as a regular expression, while {@code "\\b"} matches a
* word boundary. The string literal {@code "\(hello\)"} is illegal
* and leads to a compile-time error; in order to match the string
* {@code (hello)} the string literal {@code "\\(hello\\)"}
* must be used.
*
* <h2><a id="cc">Character Classes</a></h2>
*
* <p> Character classes may appear within other character classes, and
* may be composed by the union operator (implicit) and the intersection
* operator ({@code &&}).
* The union operator denotes a class that contains every character that is
* in at least one of its operand classes. The intersection operator
* denotes a class that contains every character that is in both of its
* operand classes.
*
* <p> The precedence of character-class operators is as follows, from
* highest to lowest:
*
* <table class="striped" style="margin-left: 2em;">
* <caption style="display:none">Precedence of character class operators.</caption>
* <thead>
* <tr><th scope="col">Precedence<th scope="col">Name<th scope="col">Example
* </thead>
* <tbody>
* <tr><th scope="row">1</th>
* <td>Literal escape </td>
* <td>{@code \x}</td></tr>
* <tr><th scope="row">2</th>
* <td>Grouping</td>
* <td>{@code [...]}</td></tr>
* <tr><th scope="row">3</th>
* <td>Range</td>
* <td>{@code a-z}</td></tr>
* <tr><th scope="row">4</th>
* <td>Union</td>
* <td>{@code [a-e][i-u]}</td></tr>
* <tr><th scope="row">5</th>
* <td>Intersection</td>
* <td>{@code [a-z&&[aeiou]]}</td></tr>
* </tbody>
* </table>
*
* <p> Note that a different set of metacharacters are in effect inside
* a character class than outside a character class. For instance, the
* regular expression {@code .} loses its special meaning inside a
* character class, while the expression {@code -} becomes a range
* forming metacharacter.
*
* <h2><a id="lt">Line terminators</a></h2>
*
* <p> A <i>line terminator</i> is a one- or two-character sequence that marks
* the end of a line of the input character sequence. The following are
* recognized as line terminators:
*
* <ul>
*
* <li> A newline (line feed) character ({@code '\n'}),
*
* <li> A carriage-return character followed immediately by a newline
* character ({@code "\r\n"}),
*
* <li> A standalone carriage-return character ({@code '\r'}),
*
* <li> A next-line character (<code>'\u0085'</code>),
*
* <li> A line-separator character (<code>'\u2028'</code>), or
*
* <li> A paragraph-separator character (<code>'\u2029'</code>).
*
* </ul>
* <p>If {@link #UNIX_LINES} mode is activated, then the only line terminators
* recognized are newline characters.
*
* <p> The regular expression {@code .} matches any character except a line
* terminator unless the {@link #DOTALL} flag is specified.
*
* <p> By default, the regular expressions {@code ^} and {@code $} ignore
* line terminators and only match at the beginning and the end, respectively,
* of the entire input sequence. If {@link #MULTILINE} mode is activated then
* {@code ^} matches at the beginning of input and after any line terminator
* except at the end of input. When in {@link #MULTILINE} mode {@code $}
* matches just before a line terminator or the end of the input sequence.
*
* <h2><a id="cg">Groups and capturing</a></h2>
*
* <h3><a id="gnumber">Group number</a></h3>
* <p> Capturing groups are numbered by counting their opening parentheses from
* left to right. In the expression {@code ((A)(B(C)))}, for example, there
* are four such groups: </p>
*
* <ol style="margin-left:2em;">
* <li> {@code ((A)(B(C)))}
* <li> {@code (A)}
* <li> {@code (B(C))}
* <li> {@code (C)}
* </ol>
*
* <p> Group zero always stands for the entire expression.
*
* <p> Capturing groups are so named because, during a match, each subsequence
* of the input sequence that matches such a group is saved. The captured
* subsequence may be used later in the expression, via a back reference, and
* may also be retrieved from the matcher once the match operation is complete.
*
* <h3><a id="groupname">Group name</a></h3>
* <p>A capturing group can also be assigned a "name", a {@code named-capturing group},
* and then be back-referenced later by the "name". Group names are composed of
* the following characters. The first character must be a {@code letter}.
*
* <ul>
* <li> The uppercase letters {@code 'A'} through {@code 'Z'}
* (<code>'\u0041'</code> through <code>'\u005a'</code>),
* <li> The lowercase letters {@code 'a'} through {@code 'z'}
* (<code>'\u0061'</code> through <code>'\u007a'</code>),
* <li> The digits {@code '0'} through {@code '9'}
* (<code>'\u0030'</code> through <code>'\u0039'</code>),
* </ul>
*
* <p> A {@code named-capturing group} is still numbered as described in
* <a href="#gnumber">Group number</a>.
*
* <p> The captured input associated with a group is always the subsequence
* that the group most recently matched. If a group is evaluated a second time
* because of quantification then its previously-captured value, if any, will
* be retained if the second evaluation fails. Matching the string
* {@code "aba"} against the expression {@code (a(b)?)+}, for example, leaves
* group two set to {@code "b"}. All captured input is discarded at the
* beginning of each match.
*
* <p> Groups beginning with {@code (?} are either pure, <i>non-capturing</i> groups
* that do not capture text and do not count towards the group total, or
* <i>named-capturing</i> group.
*
* <h2> Unicode support </h2>
*
* <p> This class is in conformance with Level 1 of <a
* href="http://www.unicode.org/reports/tr18/"><i>Unicode Technical
* Standard #18: Unicode Regular Expressions</i></a>, plus RL2.1
* Canonical Equivalents and RL2.2 Extended Grapheme Clusters.
* <p>
* <b>Unicode escape sequences</b> such as <code>\u2014</code> in Java source code
* are processed as described in section {@jls 3.3} of
* <cite>The Java Language Specification</cite>.
* Such escape sequences are also implemented directly by the regular-expression
* parser so that Unicode escapes can be used in expressions that are read from
* files or from the keyboard. Thus the strings <code>"\u2014"</code> and
* {@code "\\u2014"}, while not equal, compile into the same pattern, which
* matches the character with hexadecimal value {@code 0x2014}.
* <p>
* A Unicode character can also be represented by using its <b>Hex notation</b>
* (hexadecimal code point value) directly as described in construct
* <code>\x{...}</code>, for example a supplementary character U+2011F can be
* specified as <code>\x{2011F}</code>, instead of two consecutive Unicode escape
* sequences of the surrogate pair <code>\uD840</code><code>\uDD1F</code>.
* <p>
* <b>Unicode character names</b> are supported by the named character construct
* <code>\N{</code>...<code>}</code>, for example, <code>\N{WHITE SMILING FACE}</code>
* specifies character <code>\u263A</code>. The character names supported
* by this class are the valid Unicode character names matched by
* {@link java.lang.Character#codePointOf(String) Character.codePointOf(name)}.
* <p>
* <a href="http://www.unicode.org/reports/tr18/#Default_Grapheme_Clusters">
* <b>Unicode extended grapheme clusters</b></a> are supported by the grapheme
* cluster matcher {@code \X} and the corresponding boundary matcher {@code \b{g}}.
* <p>
* Unicode scripts, blocks, categories and binary properties are written with
* the {@code \p} and {@code \P} constructs as in Perl.
* <code>\p{</code><i>prop</i><code>}</code> matches if
* the input has the property <i>prop</i>, while <code>\P{</code><i>prop</i><code>}</code>
* does not match if the input has that property.
* <p>
* Scripts, blocks, categories and binary properties can be used both inside
* and outside of a character class.
*
* <p>
* <b><a id="usc">Scripts</a></b> are specified either with the prefix {@code Is}, as in
* {@code IsHiragana}, or by using the {@code script} keyword (or its short
* form {@code sc}) as in {@code script=Hiragana} or {@code sc=Hiragana}.
* <p>
* The script names supported by {@code Pattern} are the valid script names
* accepted and defined by
* {@link java.lang.Character.UnicodeScript#forName(String) UnicodeScript.forName}.
*
* <p>
* <b><a id="ubc">Blocks</a></b> are specified with the prefix {@code In}, as in
* {@code InMongolian}, or by using the keyword {@code block} (or its short
* form {@code blk}) as in {@code block=Mongolian} or {@code blk=Mongolian}.
* <p>
* The block names supported by {@code Pattern} are the valid block names
* accepted and defined by
* {@link java.lang.Character.UnicodeBlock#forName(String) UnicodeBlock.forName}.
* <p>
*
* <b><a id="ucc">Categories</a></b> may be specified with the optional prefix {@code Is}:
* Both {@code \p{L}} and {@code \p{IsL}} denote the category of Unicode
* letters. Same as scripts and blocks, categories can also be specified
* by using the keyword {@code general_category} (or its short form
* {@code gc}) as in {@code general_category=Lu} or {@code gc=Lu}.
* <p>
* The supported categories are those of
* <a href="http://www.unicode.org/standard/standard.html">
* <i>The Unicode Standard</i></a> in the version specified by the
* {@link java.lang.Character Character} class. The category names are those
* defined in the Standard, both normative and informative.
* <p>
*
* <b><a id="ubpc">Binary properties</a></b> are specified with the prefix {@code Is}, as in
* {@code IsAlphabetic}. The supported binary properties by {@code Pattern}
* are
* <ul>
* <li> Alphabetic
* <li> Ideographic
* <li> Letter
* <li> Lowercase
* <li> Uppercase
* <li> Titlecase
* <li> Punctuation
* <Li> Control
* <li> White_Space
* <li> Digit
* <li> Hex_Digit
* <li> Join_Control
* <li> Noncharacter_Code_Point
* <li> Assigned
* </ul>
* <p>
* The following <b>Predefined Character classes</b> and <b>POSIX character classes</b>
* are in conformance with the recommendation of <i>Annex C: Compatibility Properties</i>
* of <a href="http://www.unicode.org/reports/tr18/"><i>Unicode Technical Standard #18:
* Unicode Regular Expressions</i></a>, when {@link #UNICODE_CHARACTER_CLASS} flag is specified.
*
* <table class="striped">
* <caption style="display:none">predefined and posix character classes in Unicode mode</caption>
* <thead>
* <tr>
* <th scope="col" id="predef_classes">Classes</th>
* <th scope="col" id="predef_matches">Matches</th>
* </tr>
* </thead>
* <tbody>
* <tr><th scope="row">{@code \p{Lower}}</th>
* <td>A lowercase character:{@code \p{IsLowercase}}</td></tr>
* <tr><th scope="row">{@code \p{Upper}}</th>
* <td>An uppercase character:{@code \p{IsUppercase}}</td></tr>
* <tr><th scope="row">{@code \p{ASCII}}</th>
* <td>All ASCII:{@code [\x00-\x7F]}</td></tr>
* <tr><th scope="row">{@code \p{Alpha}}</th>
* <td>An alphabetic character:{@code \p{IsAlphabetic}}</td></tr>
* <tr><th scope="row">{@code \p{Digit}}</th>
* <td>A decimal digit character:{@code \p{IsDigit}}</td></tr>
* <tr><th scope="row">{@code \p{Alnum}}</th>
* <td>An alphanumeric character:{@code [\p{IsAlphabetic}\p{IsDigit}]}</td></tr>
* <tr><th scope="row">{@code \p{Punct}}</th>
* <td>A punctuation character:{@code \p{IsPunctuation}}</td></tr>
* <tr><th scope="row">{@code \p{Graph}}</th>
* <td>A visible character: {@code [^\p{IsWhite_Space}\p{gc=Cc}\p{gc=Cs}\p{gc=Cn}]}</td></tr>
* <tr><th scope="row">{@code \p{Print}}</th>
* <td>A printable character: {@code [\p{Graph}\p{Blank}&&[^\p{Cntrl}]]}</td></tr>
* <tr><th scope="row">{@code \p{Blank}}</th>
* <td>A space or a tab: {@code [\p{IsWhite_Space}&&[^\p{gc=Zl}\p{gc=Zp}\x0a\x0b\x0c\x0d\x85]]}</td></tr>
* <tr><th scope="row">{@code \p{Cntrl}}</th>
* <td>A control character: {@code \p{gc=Cc}}</td></tr>
* <tr><th scope="row">{@code \p{XDigit}}</th>
* <td>A hexadecimal digit: {@code [\p{gc=Nd}\p{IsHex_Digit}]}</td></tr>
* <tr><th scope="row">{@code \p{Space}}</th>
* <td>A whitespace character:{@code \p{IsWhite_Space}}</td></tr>
* <tr><th scope="row">{@code \d}</th>
* <td>A digit: {@code \p{IsDigit}}</td></tr>
* <tr><th scope="row">{@code \D}</th>
* <td>A non-digit: {@code [^\d]}</td></tr>
* <tr><th scope="row">{@code \s}</th>
* <td>A whitespace character: {@code \p{IsWhite_Space}}</td></tr>
* <tr><th scope="row">{@code \S}</th>
* <td>A non-whitespace character: {@code [^\s]}</td></tr>
* <tr><th scope="row">{@code \w}</th>
* <td>A word character: {@code [\p{Alpha}\p{gc=Mn}\p{gc=Me}\p{gc=Mc}\p{Digit}\p{gc=Pc}\p{IsJoin_Control}]}</td></tr>
* <tr><th scope="row">{@code \W}</th>
* <td>A non-word character: {@code [^\w]}</td></tr>
* </tbody>
* </table>
* <p>
* <a id="jcc">
* Categories that behave like the java.lang.Character
* boolean is<i>methodname</i> methods (except for the deprecated ones) are
* available through the same <code>\p{</code><i>prop</i><code>}</code> syntax where
* the specified property has the name <code>java<i>methodname</i></code></a>.
*
* <h2> Comparison to Perl 5 </h2>
*
* <p>The {@code Pattern} engine performs traditional NFA-based matching
* with ordered alternation as occurs in Perl 5.
*
* <p> Perl constructs not supported by this class: </p>
*
* <ul>
* <li><p> The backreference constructs, <code>\g{</code><i>n</i><code>}</code> for
* the <i>n</i><sup>th</sup><a href="#cg">capturing group</a> and
* <code>\g{</code><i>name</i><code>}</code> for
* <a href="#groupname">named-capturing group</a>.
* </p></li>
*
* <li><p> The conditional constructs
* {@code (?(}<i>condition</i>{@code )}<i>X</i>{@code )} and
* {@code (?(}<i>condition</i>{@code )}<i>X</i>{@code |}<i>Y</i>{@code )},
* </p></li>
*
* <li><p> The embedded code constructs <code>(?{</code><i>code</i><code>})</code>
* and <code>(??{</code><i>code</i><code>})</code>,</p></li>
*
* <li><p> The embedded comment syntax {@code (?#comment)}, and </p></li>
*
* <li><p> The preprocessing operations {@code \l} <code>\u</code>,
* {@code \L}, and {@code \U}. </p></li>
*
* </ul>
*
* <p> Constructs supported by this class but not by Perl: </p>
*
* <ul>
*
* <li><p> Character-class union and intersection as described
* <a href="#cc">above</a>.</p></li>
*
* </ul>
*
* <p> Notable differences from Perl: </p>
*
* <ul>
*
* <li><p> In Perl, {@code \1} through {@code \9} are always interpreted
* as back references; a backslash-escaped number greater than {@code 9} is
* treated as a back reference if at least that many subexpressions exist,
* otherwise it is interpreted, if possible, as an octal escape. In this
* class octal escapes must always begin with a zero. In this class,
* {@code \1} through {@code \9} are always interpreted as back
* references, and a larger number is accepted as a back reference if at
* least that many subexpressions exist at that point in the regular
* expression, otherwise the parser will drop digits until the number is
* smaller or equal to the existing number of groups or it is one digit.
* </p></li>
*
* <li><p> Perl uses the {@code g} flag to request a match that resumes
* where the last match left off. This functionality is provided implicitly
* by the {@link Matcher} class: Repeated invocations of the {@link
* Matcher#find find} method will resume where the last match left off,
* unless the matcher is reset. </p></li>
*
* <li><p> In Perl, embedded flags at the top level of an expression affect
* the whole expression. In this class, embedded flags always take effect
* at the point at which they appear, whether they are at the top level or
* within a group; in the latter case, flags are restored at the end of the
* group just as in Perl. </p></li>
*
* <li><p><i>Free-spacing mode</i> in Perl (called <i>comments
* mode</i> in this class) denoted by {@code (?x)} in the regular
* expression (or by the {@link Pattern#COMMENTS} flag when compiling
* the expression) will not ignore whitespace inside of character classes. In
* this class, whitespace inside of character classes must be escaped to be
* considered as part of the regular expression when in comments mode.
* </p></li>
*
* </ul>
*
*
* <p> For a more precise description of the behavior of regular expression
* constructs, please see <a href="http://www.oreilly.com/catalog/regex3/">
* <i>Mastering Regular Expressions, 3rd Edition</i>, Jeffrey E. F. Friedl,
* O'Reilly and Associates, 2006.</a>
* </p>
*
* @see java.lang.String#split(String, int)
* @see java.lang.String#split(String)
*
* @author Mike McCloskey
* @author Mark Reinhold
* @author JSR-51 Expert Group
* @since 1.4
*/
public final class Pattern
implements java.io.Serializable
{
/*
* Regular expression modifier values. Instead of being passed as
* arguments, they can also be passed as inline modifiers.
* For example, the following statements have the same effect.
*
* Pattern p1 = Pattern.compile("abc", Pattern.CASE_INSENSITIVE|Pattern.MULTILINE);
* Pattern p2 = Pattern.compile("(?im)abc", 0);
*/
/**
* Enables Unix lines mode.
*
* <p> In this mode, only the {@code '\n'} line terminator is recognized
* in the behavior of {@code .}, {@code ^}, and {@code $}.
*
* <p> Unix lines mode can also be enabled via the embedded flag
* expression {@code (?d)}.
*/
public static final int UNIX_LINES = 0x01;
/**
* Enables case-insensitive matching.
*
* <p> By default, case-insensitive matching assumes that only characters
* in the US-ASCII charset are being matched. Unicode-aware
* case-insensitive matching can be enabled by specifying the {@link
* #UNICODE_CASE} flag in conjunction with this flag.
*
* <p> Case-insensitive matching can also be enabled via the embedded flag
* expression {@code (?i)}.
*
* <p> Specifying this flag may impose a slight performance penalty. </p>
*/
public static final int CASE_INSENSITIVE = 0x02;
/**
* Permits whitespace and comments in pattern.
*
* <p> In this mode, whitespace is ignored, and embedded comments starting
* with {@code #} are ignored until the end of a line. Comments mode ignores
* whitespace within a character class contained in a pattern string. Such
* whitespace must be escaped in order to be considered significant. </p>
*
* <p> Comments mode can also be enabled via the embedded flag
* expression {@code (?x)}.
*/
public static final int COMMENTS = 0x04;
/**
* Enables multiline mode.
*
* <p> In multiline mode the expressions {@code ^} and {@code $} match
* just after or just before, respectively, a line terminator or the end of
* the input sequence. By default these expressions only match at the
* beginning and the end of the entire input sequence.
*
* <p> Multiline mode can also be enabled via the embedded flag
* expression {@code (?m)}. </p>
*/
public static final int MULTILINE = 0x08;
/**
* Enables literal parsing of the pattern.
*
* <p> When this flag is specified then the input string that specifies
* the pattern is treated as a sequence of literal characters.
* Metacharacters or escape sequences in the input sequence will be
* given no special meaning.
*
* <p>The flags CASE_INSENSITIVE and UNICODE_CASE retain their impact on
* matching when used in conjunction with this flag. The other flags
* become superfluous.
*
* <p> There is no embedded flag character for enabling literal parsing.
* @since 1.5
*/
public static final int LITERAL = 0x10;
/**
* Enables dotall mode.
*
* <p> In dotall mode, the expression {@code .} matches any character,
* including a line terminator. By default this expression does not match
* line terminators.
*
* <p> Dotall mode can also be enabled via the embedded flag
* expression {@code (?s)}. (The {@code s} is a mnemonic for
* "single-line" mode, which is what this is called in Perl.) </p>
*/
public static final int DOTALL = 0x20;
/**
* Enables Unicode-aware case folding.
*
* <p> When this flag is specified then case-insensitive matching, when
* enabled by the {@link #CASE_INSENSITIVE} flag, is done in a manner
* consistent with the Unicode Standard. By default, case-insensitive
* matching assumes that only characters in the US-ASCII charset are being
* matched.
*
* <p> Unicode-aware case folding can also be enabled via the embedded flag
* expression {@code (?u)}.
*
* <p> Specifying this flag may impose a performance penalty. </p>
*/
public static final int UNICODE_CASE = 0x40;
/**
* Enables canonical equivalence.
*
* <p> When this flag is specified then two characters will be considered
* to match if, and only if, their full canonical decompositions match.
* The expression <code>"a\u030A"</code>, for example, will match the
* string <code>"\u00E5"</code> when this flag is specified. By default,
* matching does not take canonical equivalence into account.
*
* <p> There is no embedded flag character for enabling canonical
* equivalence.
*
* <p> Specifying this flag may impose a performance penalty. </p>
*/
public static final int CANON_EQ = 0x80;
/**
* Enables the Unicode version of <i>Predefined character classes</i> and
* <i>POSIX character classes</i>.
*
* <p> When this flag is specified then the (US-ASCII only)
* <i>Predefined character classes</i> and <i>POSIX character classes</i>
* are in conformance with
* <a href="http://www.unicode.org/reports/tr18/"><i>Unicode Technical
* Standard #18: Unicode Regular Expressions</i></a>
* <i>Annex C: Compatibility Properties</i>.
* <p>
* The UNICODE_CHARACTER_CLASS mode can also be enabled via the embedded
* flag expression {@code (?U)}.
* <p>
* The flag implies UNICODE_CASE, that is, it enables Unicode-aware case
* folding.
* <p>
* Specifying this flag may impose a performance penalty. </p>
* @since 1.7
*/
public static final int UNICODE_CHARACTER_CLASS = 0x100;
/**
* Contains all possible flags for compile(regex, flags).
*/
private static final int ALL_FLAGS = CASE_INSENSITIVE | MULTILINE |
DOTALL | UNICODE_CASE | CANON_EQ | UNIX_LINES | LITERAL |
UNICODE_CHARACTER_CLASS | COMMENTS;
/* Pattern has only two serialized components: The pattern string
* and the flags, which are all that is needed to recompile the pattern
* when it is deserialized.
*/
/** use serialVersionUID from Merlin b59 for interoperability */
@java.io.Serial
private static final long serialVersionUID = 5073258162644648461L;
/**
* The original regular-expression pattern string.
*
* @serial
*/
private String pattern;
/**
* The original pattern flags.
*
* @serial
*/
private int flags;
/**
* The temporary pattern flags used during compiling. The flags might be turn
* on and off by embedded flag.
*/
private transient int flags0;
/**
* Boolean indicating this Pattern is compiled; this is necessary in order
* to lazily compile deserialized Patterns.
*/
private transient volatile boolean compiled;
/**
* The normalized pattern string.
*/
private transient String normalizedPattern;
/**
* The starting point of state machine for the find operation. This allows
* a match to start anywhere in the input.
*/
transient Node root;
/**
* The root of object tree for a match operation. The pattern is matched
* at the beginning. This may include a find that uses BnM or a First
* node.
*/
transient Node matchRoot;
/**
* Temporary storage used by parsing pattern slice.
*/
transient int[] buffer;
/**
* A temporary storage used for predicate for double return.
*/