@@ -113,6 +113,7 @@ function serveTest(query, response)
113
113
{
114
114
response . write ( JSON . stringify ( { "success" : false , "message" : "no input" } ) ) ;
115
115
response . end ( ) ;
116
+ return ;
116
117
}
117
118
118
119
var retVal = { } ;
@@ -123,9 +124,6 @@ function serveTest(query, response)
123
124
124
125
try
125
126
{
126
-
127
-
128
-
129
127
var params = { } ;
130
128
var pairs = query . split ( "&" ) ;
131
129
for ( var loop = 0 ; loop < pairs . length ; loop ++ )
@@ -155,11 +153,13 @@ function serveTest(query, response)
155
153
{
156
154
response . write ( JSON . stringify ( { "success" : false , "message" : "No regex to test!" } ) ) ;
157
155
response . end ( ) ;
156
+ return ;
158
157
}
159
158
160
159
var replacement = 'replacement' in params ? params [ 'replacement' ] [ 0 ] : null ;
161
160
var str_options = "" ;
162
161
var options = 'option' in params ? params [ 'option' ] : null ;
162
+ var global = false ;
163
163
if ( options != null && options . length > 0 )
164
164
{
165
165
for ( var loop = 0 ; loop < options . length ; loop ++ )
@@ -168,6 +168,7 @@ function serveTest(query, response)
168
168
169
169
if ( option == "global" )
170
170
{
171
+ global = true ;
171
172
str_options += "g" ;
172
173
}
173
174
else if ( option == "multiline" )
@@ -209,11 +210,11 @@ function serveTest(query, response)
209
210
html . push ( "\t</tr>\n" ) ;
210
211
html . push ( "</table>\n" ) ;
211
212
212
- var regex = null ;
213
+ var compileTest = null ;
213
214
214
215
try
215
216
{
216
- regex = new RegExp ( str_regex , str_options ) ;
217
+ compileTest = new RegExp ( str_regex , str_options ) ;
217
218
}
218
219
catch ( err )
219
220
{
@@ -222,6 +223,7 @@ function serveTest(query, response)
222
223
html . push ( "</div>" ) ;
223
224
response . write ( JSON . stringify ( { "success" : true , "message" : "unable to create RegExp object" , "html" : html . join ( "" ) } ) ) ;
224
225
response . end ( ) ;
226
+ return ;
225
227
}
226
228
227
229
html . push ( '<table class=\"table table-bordered table-striped\">\n' ) ;
@@ -230,10 +232,11 @@ function serveTest(query, response)
230
232
html . push ( "\t\t<tr>\n" ) ;
231
233
html . push ( "\t\t\t<th style=\"text-align:center;\">Test</th>\n" ) ;
232
234
html . push ( "\t\t\t<th>Input</th>" ) ;
233
- html . push ( "\t\t\t<th>.test()</th>" ) ;
235
+ html . push ( "\t\t\t<th>input.replace</th>" ) ;
236
+ html . push ( "\t\t\t<th>input.split</th>" ) ;
237
+ html . push ( "\t\t\t<th>regex.test()</th>" ) ;
234
238
html . push ( "\t\t\t<th>regex.exec().index</th>" ) ;
235
- html . push ( "\t\t\t<th>regex.exec()[0]</th>" ) ;
236
- html . push ( "\t\t\t<th>regex.exec()[1..n]</th>" ) ;
239
+ html . push ( "\t\t\t<th>regex.exec()[]</th>" ) ;
237
240
html . push ( "\t\t\t<th>regex.lastIndex</th>" ) ;
238
241
html . push ( "\t\t</tr>\n" ) ;
239
242
html . push ( "\t</thead>\n" ) ;
@@ -263,14 +266,31 @@ function serveTest(query, response)
263
266
html . push ( h ( input ) ) ;
264
267
html . push ( "</td>\n" ) ;
265
268
269
+ html . push ( '\t\t\t<td>' ) ;
270
+ html . push ( h ( input . replace ( new RegExp ( str_regex , str_options ) , replacement == null ? "" : replacement ) ) ) ;
271
+ html . push ( "</td>\n" ) ;
272
+
273
+ html . push ( '\t\t\t<td>' ) ;
274
+ var splits = input . split ( new RegExp ( str_regex , str_options ) ) ;
275
+ for ( var split = 0 ; split < splits . length ; split ++ )
276
+ {
277
+ html . push ( "[" ) ;
278
+ html . push ( split ) ;
279
+ html . push ( "]: " ) ;
280
+ html . push ( splits [ split ] == null ? "<i>(null)</i>" : h ( splits [ split ] ) ) ;
281
+ html . push ( "<br/>" ) ;
282
+ }
283
+ html . push ( "</td>\n" ) ;
284
+
266
285
html . push ( '\t\t\t<td>' ) ;
267
286
html . push ( new RegExp ( str_regex , str_options ) . test ( input ) ? "true" : "false" ) ; // can't use the same object twice
268
287
html . push ( "</td>\n" ) ;
269
288
289
+ var regex = new RegExp ( str_regex , str_options ) ;
270
290
var result = regex . exec ( input ) ;
271
291
if ( result == null )
272
292
{
273
- html . push ( '\t\t\t<td colspan="4 "><i>(null)</i></td>\n' ) ;
293
+ html . push ( '\t\t\t<td colspan="6 "><i>(null)</i></td>\n' ) ;
274
294
}
275
295
else
276
296
{
@@ -285,7 +305,7 @@ function serveTest(query, response)
285
305
else
286
306
{
287
307
html . push ( "</tr>\n" ) ;
288
- html . push ( '\t\t\t<td colspan="3 " style="text-align:right;">' ) ;
308
+ html . push ( '\t\t\t<td colspan="5 " style="text-align:right;">' ) ;
289
309
html . push ( "regex.exec()" ) ;
290
310
html . push ( "</td>\n" ) ;
291
311
}
@@ -295,14 +315,11 @@ function serveTest(query, response)
295
315
html . push ( "</td>\n" ) ;
296
316
297
317
html . push ( '\t\t\t<td>' ) ;
298
- html . push ( result [ 0 ] ) ;
299
- html . push ( "</td>\n" ) ;
300
-
301
- html . push ( '\t\t\t<td>' ) ;
302
- for ( var capture = 1 ; capture < result . length ; capture ++ )
318
+ for ( var capture = 0 ; capture < result . length ; capture ++ )
303
319
{
320
+ html . push ( "[" ) ;
304
321
html . push ( capture ) ;
305
- html . push ( ": " ) ;
322
+ html . push ( "] : " ) ;
306
323
html . push ( result [ capture ] == null ? "<i>(null)</i>" : h ( result [ capture ] ) ) ;
307
324
html . push ( "<br/>" ) ;
308
325
}
@@ -312,10 +329,10 @@ function serveTest(query, response)
312
329
html . push ( regex . lastIndex ) ;
313
330
html . push ( "</td>\n" ) ;
314
331
315
- result = regex . exec ( input ) ;
332
+ result = global ? regex . exec ( input ) : null ;
316
333
}
317
- }
318
334
335
+ }
319
336
html . push ( "\t\t</tr>\n" ) ;
320
337
count ++ ;
321
338
}
@@ -324,7 +341,7 @@ function serveTest(query, response)
324
341
if ( count == 0 )
325
342
{
326
343
html . push ( "\t\t<tr>\n" ) ;
327
- html . push ( '\t\t<td colspan="4 "><i>' ) ;
344
+ html . push ( '\t\t<td colspan="8 "><i>' ) ;
328
345
html . push ( "(no input to test)" ) ;
329
346
html . push ( "</i></td>\n" ) ;
330
347
html . push ( "\t\t</tr>\n" ) ;
0 commit comments