@@ -20,7 +20,7 @@ public static RegExp of() {
2020
2121
2222 // -------------------------
23- // COMPLEX
23+ // GROUP
2424
2525 private RegExp startGroup (String name ) {
2626 regExpString += "(" ;
@@ -66,71 +66,216 @@ public int indexOf(String name) {
6666 // -------------------------
6767 // PATTERN
6868
69- public RegExp text (String match ) {
70- regExpString += escape (match );
69+ /**
70+ * Match a specific text.
71+ * Any characters with special meaning in regular expressions will be escape.
72+ * @param s the text to match, it does not need to be (regexp) escaped.
73+ * @return
74+ */
75+ public RegExp text (String s ) {
76+ regExpString += escape (s );
77+ return this ;
78+ }
79+
80+ /**
81+ * Match a range of text.
82+ * Any characters with special meaning in regular expressions will be escape.
83+ * @param fromChar the beginning character
84+ * @param toChar the beginning character
85+ * @return
86+ */
87+ public RegExp range (String fromChar , String toChar ) {
88+ if (fromChar .length () != 1 || toChar .length () != 1 ) {
89+ throw new IllegalArgumentException ("The character parameters must be exactly 1 in length" );
90+ }
91+ regExpString += "[" + escape (fromChar ) + "-" + escape (toChar ) + "]" ;
7192 return this ;
7293 }
7394
95+ /**
96+ * Match one of the characters
97+ * @param regExp
98+ * @return
99+ */
74100 public RegExp oneOf (RegExp regExp ) {
75101 regExpString += "[" + regExp .toString () + "]" ;
76102 return this ;
77103 }
78- public RegExp oneOf (String match ) {
79- return oneOf (RegExp .of ().text (match ));
104+ /**
105+ * Match one of the characters
106+ * @param s
107+ * @return
108+ */
109+ public RegExp oneOf (String s ) {
110+ return oneOf (RegExp .of ().text (s ));
80111 }
81112
113+ /**
114+ * Match any character but the specified ones
115+ * @param regExp
116+ * @return
117+ */
82118 public RegExp notOneOf (RegExp regExp ) {
83119 regExpString += "[^" + regExp .toString () + "]" ;
84120 return this ;
85121 }
86- public RegExp notOneOf (String match ) {
87- return notOneOf (RegExp .of ().text (match ));
122+ /**
123+ * Match any character but the specified ones
124+ * @param s
125+ * @return
126+ */
127+ public RegExp notOneOf (String s ) {
128+ return notOneOf (RegExp .of ().text (s ));
88129 }
89130
131+ /**
132+ * These characters may be present, or not.
133+ * @param regExp
134+ * @return
135+ */
90136 public RegExp optional (RegExp regExp ) {
91137 regExpString += regExp .toString () + "?" ;
92138 return this ;
93139 }
140+ /**
141+ * These characters may be present, or not.
142+ * @param s
143+ * @return
144+ */
94145 public RegExp optional (String s ) {
95146 return optional (RegExp .of ().text (s ));
96147 }
97148
149+ /**
150+ * These characters can not be present, or once, or many times
151+ * @param regExp
152+ * @return
153+ */
98154 public RegExp zeroOrMore (RegExp regExp ) {
99155 regExpString += regExp .toString () + "*" ;
100156 return this ;
101157 }
158+
159+ /**
160+ * These characters can not be present, or once, or many times
161+ * @param s
162+ * @return
163+ */
102164 public RegExp zeroOrMore (String s ) {
103165 return zeroOrMore (RegExp .of ().text (s ));
104166 }
105167
168+ /**
169+ * These characters must be present once, but can be many times
170+ * @param regExp
171+ * @return
172+ */
106173 public RegExp oneOrMore (RegExp regExp ) {
107174 regExpString += regExp .toString () + "+" ;
108175 return this ;
109176 }
177+ /**
178+ * These characters must be present once, but can be many times
179+ * @param s
180+ * @return
181+ */
110182 public RegExp oneOrMore (String s ) {
111183 return oneOrMore (RegExp .of ().text (s ));
112184 }
113185
186+ /**
187+ * Match any of the blocks of characters
188+ * @param regExps
189+ * @return
190+ */
191+ public RegExp anyOf (RegExp ... regExps ) {
192+ boolean first = true ;
193+ for (RegExp regExp : regExps ) {
194+ regExpString += (first ? "" : "|" ) + regExp .toString ();
195+ first = false ;
196+ }
197+ return this ;
198+ }
199+ /**
200+ * Match any of the blocks of characters
201+ * @param ss
202+ * @return
203+ */
204+ public RegExp anyOf (String ... ss ) {
205+ RegExp [] regExps = new RegExp [ss .length ];
206+ for (int i = 0 ; i < ss .length ; i ++) {
207+ regExps [i ] = RegExp .of ().text (ss [i ]);
208+ }
209+ return anyOf (regExps );
210+ }
211+ /**
212+ * Match any of the blocks of characters
213+ * @param objects must be a RegExp or otherwise it will be converted to a string
214+ * @return
215+ */
216+ public RegExp anyOf (Object ... objects ) {
217+ RegExp [] regExps = new RegExp [objects .length ];
218+ for (int i = 0 ; i < objects .length ; i ++) {
219+ if (objects [i ] instanceof RegExp regExp ) {
220+ regExps [i ] = regExp ;
221+ }
222+ else {
223+ regExps [i ] = RegExp .of ().text (objects [i ].toString ());
224+ }
225+ }
226+ return anyOf (regExps );
227+ }
228+
229+ /**
230+ * These characters are present N times
231+ * @param regExp
232+ * @return
233+ */
114234 public RegExp occurs (int times , RegExp regExp ) {
115235 regExpString += regExp .toString () + "{" + times + "}" ;
116236 return this ;
117237 }
238+ /**
239+ * These characters are present N times
240+ * @param s
241+ * @return
242+ */
118243 public RegExp occurs (int times , String s ) {
119244 return occurs (times , RegExp .of ().text (s ));
120245 }
121246
247+ /**
248+ * These characters are present at least N times
249+ * @param regExp
250+ * @return
251+ */
122252 public RegExp occursAtLeast (int times , RegExp regExp ) {
123253 regExpString += regExp .toString () + "{" + times + ",}" ;
124254 return this ;
125255 }
256+ /**
257+ * These characters are present at least N times
258+ * @param s
259+ * @return
260+ */
126261 public RegExp occursAtLeast (int times , String s ) {
127262 return occursAtLeast (times , RegExp .of ().text (s ));
128263 }
129264
265+ /**
266+ * These characters are present N to M times
267+ * @param regExp
268+ * @return
269+ */
130270 public RegExp occursBetween (int minTimes , int maxTimes , RegExp regExp ) {
131271 regExpString += regExp .toString () + "{" + minTimes + "," + maxTimes + "}" ;
132272 return this ;
133273 }
274+ /**
275+ * These characters are present N to M times
276+ * @param s
277+ * @return
278+ */
134279 public RegExp occursBetween (int minTimes , int maxTimes , String s ) {
135280 return occursBetween (minTimes , maxTimes , RegExp .of ().text (s ));
136281 }
0 commit comments