| 1 |
#include "tads.h" |
| 2 |
#include "t3.h" |
| 3 |
|
| 4 |
preinit() { } |
| 5 |
|
| 6 |
main(args) |
| 7 |
{ |
| 8 |
local alloc = (args.indexOf('-alloc') != nil); |
| 9 |
if (alloc) |
| 10 |
"(Allocating RexPattern objects.)\n"; |
| 11 |
|
| 12 |
"args = [<<args.join(', ')>>]\n"; |
| 13 |
|
| 14 |
for (;;) |
| 15 |
{ |
| 16 |
local pat, str, match; |
| 17 |
|
| 18 |
"regular expression: "; pat = inputLine(); |
| 19 |
if (pat == '') |
| 20 |
break; |
| 21 |
|
| 22 |
if (alloc) |
| 23 |
pat = new RexPattern(pat); |
| 24 |
|
| 25 |
"string: "; str = inputLine(); |
| 26 |
|
| 27 |
match = rexSearch(pat, str); |
| 28 |
if (match == nil) |
| 29 |
"No match.\n"; |
| 30 |
else |
| 31 |
{ |
| 32 |
"Match=[<<match[3]>>] (ofs <<match[1]>>, len <<match[2]>>)\n"; |
| 33 |
for (local i = 1 ; i < 9 ; ++i) |
| 34 |
{ |
| 35 |
local g = rexGroup(i); |
| 36 |
if (g != nil) |
| 37 |
"group <<i>> = '<<g[3]>>'\n"; |
| 38 |
} |
| 39 |
} |
| 40 |
|
| 41 |
"\b"; |
| 42 |
} |
| 43 |
} |