@@ -32,35 +32,43 @@ console.log(result); // ['a', 'b']
3232The syntax is similar to regular expressions and its composed by just a few
3333different tokens.
3434
35+ ### Literals
36+
3537Literal strings output themselves:
3638
3739```
3840a => ['a']
3941```
4042
43+ ### Optional characters
44+
4145Optional characters are followed by a ` ? ` :
4246
4347```
4448ab? => ['a', 'ab']
4549```
4650
51+ ### Groups
52+
4753Groups are used to group options. The group is defined by parentheses and the
4854options are separated by ` | ` :
4955
5056```
5157(a|b) => ['a', 'b']
5258```
5359
54- Optional groups are followed by a ` ? ` :
60+ Groups can have a single option :
5561
5662```
57- (a|b)? => ['a', 'b', ' ']
63+ (a) => ['a']
5864```
5965
60- Groups can have a single option:
66+ ### Optional groups
67+
68+ Optional groups are followed by a ` ? ` :
6169
6270```
63- (a) => ['a']
71+ (a|b)? => ['a', 'b', ' ']
6472```
6573
6674You can use a single-option group combined with the optional character ` ? ` to
@@ -70,27 +78,56 @@ make more than one character optional:
7078(ab)? => ['ab', '']
7179```
7280
81+ ### Nested groups
82+
7383Groups can be nested:
7484
7585```
7686(a(b|c)) => ['ab', 'ac']
7787```
7888
89+ ### Inclusive groups
90+
91+ You can also use inclusive groups (or simply igroups) by using a plus sign (` + ` )
92+ before the options. Different from the standard groups, igroups also output an
93+ option that concatenates all of its options:
94+
95+ ```
96+ (+a|b) => ['a', 'b', 'ab']
97+ ```
98+
99+ As with standard groups, igroups can be optional:
100+
101+ ```
102+ (+a|b)? => ['a', 'b', 'ab', '']
103+ ```
104+
105+ Igroups can also be nested:
106+
107+ ```
108+ (+a|(+b|c)) => ['a', 'ab', 'abc', 'ac', 'b', 'bc', 'c']
109+ ```
110+
111+ ### Complex patterns
112+
79113Finally, you can mix all of them into complex patterns:
80114
81115```
82116Mary( Eli(z|s)abeth)?( Simmons)? Smith(son)? => [
83- 'Mary Elizabeth Simmons Smithson',
84- 'Mary Elizabeth Simmons Smith',
85- 'Mary Elizabeth Smithson',
86- 'Mary Elizabeth Smith',
87- 'Mary Elisabeth Simmons Smithson',
117+ 'Mary Elisabeth Simmons',
88118 'Mary Elisabeth Simmons Smith',
89- 'Mary Elisabeth Smithson',
119+ 'Mary Elisabeth Simmons Smithson',
90120 'Mary Elisabeth Smith',
91- 'Mary Simmons Smithson',
121+ 'Mary Elisabeth Smithson',
122+ 'Mary Elizabeth Simmons',
123+ 'Mary Elizabeth Simmons Smith',
124+ 'Mary Elizabeth Simmons Smithson',
125+ 'Mary Elizabeth Smith',
126+ 'Mary Elizabeth Smithson',
127+ 'Mary Simmons',
92128 'Mary Simmons Smith',
129+ 'Mary Simmons Smithson',
130+ 'Mary Smith',
93131 'Mary Smithson',
94- 'Mary Smith'
95132]
96133```
0 commit comments