|
Revision 292, 1.1 kB
(checked in by JarrettBillingsley, 7 months ago)
|
Closes #65. Also fixed a bug in the regexp.email predefined regexp, and a small bug in dumpVal.
|
| Line | |
|---|
| 1 |
module regexptest |
|---|
| 2 |
|
|---|
| 3 |
function main() |
|---|
| 4 |
{ |
|---|
| 5 |
writefln(regexp.test(@"^\d+$","1232131")) |
|---|
| 6 |
writefln(regexp.test(@"^\d+$","abcee")) |
|---|
| 7 |
writefln(regexp.test(regexp.cnMobile,"13903113456")) |
|---|
| 8 |
writefln(regexp.test(regexp.chinese,"中文为真")) |
|---|
| 9 |
|
|---|
| 10 |
writefln() |
|---|
| 11 |
|
|---|
| 12 |
foreach(v; regexp.split("ab","this is ab test, fa ab to.")) |
|---|
| 13 |
writefln(v) |
|---|
| 14 |
|
|---|
| 15 |
writefln() |
|---|
| 16 |
|
|---|
| 17 |
local temail = |
|---|
| 18 |
{ |
|---|
| 19 |
fork = "ideage@gmail.com", |
|---|
| 20 |
knife = "abd@12.com", |
|---|
| 21 |
spoon = "abd@12.com", |
|---|
| 22 |
spatula = "crappy" |
|---|
| 23 |
} |
|---|
| 24 |
|
|---|
| 25 |
local r = regexp.compile(regexp.email) |
|---|
| 26 |
|
|---|
| 27 |
foreach(k, v; temail) |
|---|
| 28 |
{ |
|---|
| 29 |
writefln("T[", k, "] = ", v) |
|---|
| 30 |
|
|---|
| 31 |
if(!r.test(v)) |
|---|
| 32 |
writefln("Error!") |
|---|
| 33 |
else |
|---|
| 34 |
writefln("OK!") |
|---|
| 35 |
} |
|---|
| 36 |
|
|---|
| 37 |
writefln() |
|---|
| 38 |
|
|---|
| 39 |
foreach(i, m; regexp.compile("ab").search("abcabcabab")) |
|---|
| 40 |
writefln(i, ": {}[{}]{}", m.pre(), m.match(0), m.post()) |
|---|
| 41 |
|
|---|
| 42 |
writefln(); |
|---|
| 43 |
|
|---|
| 44 |
local phone = regexp.compile(regexp.usPhone) |
|---|
| 45 |
|
|---|
| 46 |
writefln(phone.test("1-800-456-7890")) |
|---|
| 47 |
writefln(phone.test("987-654-3210")) |
|---|
| 48 |
writefln(phone.test("12-234-345-4567")) |
|---|
| 49 |
writefln(phone.test("555-1234")) |
|---|
| 50 |
|
|---|
| 51 |
writefln() |
|---|
| 52 |
|
|---|
| 53 |
writefln(regexp.test(regexp.hexdigit, "3289Ab920Df")) |
|---|
| 54 |
} |
|---|