| 1 |
BEGIN { |
| 2 |
print "Initialize strong regex" |
| 3 |
rgx2 = rgx1 = @/[abc]/ |
| 4 |
print "Test gsub on strong regex" |
| 5 |
printf("rgx%d = '%s'\ttypeof(rgx%d) = '%s'\n", 1, rgx1, 1, typeof(rgx1)) |
| 6 |
printf("rgx%d = '%s'\ttypeof(rgx%d) = '%s'\n", 2, rgx2, 2, typeof(rgx2)) |
| 7 |
print "Test gsub() a strong regex" |
| 8 |
gsub(/b/, "e", rgx2) |
| 9 |
printf("rgx%d = '%s'\ttypeof(rgx%d) = '%s'\n", 1, rgx1, 1, typeof(rgx1)) |
| 10 |
printf("rgx%d = '%s'\ttypeof(rgx%d) = '%s'\n", 2, rgx2, 2, typeof(rgx2)) |
| 11 |
|
| 12 |
print "Test value not found in regex" |
| 13 |
gsub(/x/, "y", rgx1) # should not change |
| 14 |
printf("rgx%d = '%s'\ttypeof(rgx%d) = '%s'\n", 1, rgx1, 1, typeof(rgx1)) |
| 15 |
|
| 16 |
print "Test gsub on numbers" |
| 17 |
v2 = v1 = 12345 |
| 18 |
printf("v%d = '%s'\ttypeof(v%d) = '%s'\n", 1, v1, 1, typeof(v1)) |
| 19 |
printf("v%d = '%s'\ttypeof(v%d) = '%s'\n", 2, v2, 2, typeof(v2)) |
| 20 |
gsub(/3/, "x", v2) |
| 21 |
printf("v%d = '%s'\ttypeof(v%d) = '%s'\n", 1, v1, 1, typeof(v1)) |
| 22 |
printf("v%d = '%s'\ttypeof(v%d) = '%s'\n", 2, v2, 2, typeof(v2)) |
| 23 |
print "Test value not found in number" |
| 24 |
gsub(/9/, "x", v1) |
| 25 |
printf("v%d = '%s'\ttypeof(v%d) = '%s'\n", 1, v1, 1, typeof(v1)) |
| 26 |
|
| 27 |
print "Test gensub on regex" |
| 28 |
a = b = @/abc/ |
| 29 |
c = gensub(/b/, "x", "g", a) |
| 30 |
printf("a = @/%s/\ttypeof(a) = '%s'\n", a, typeof(a)) |
| 31 |
printf("c = \"%s\"\ttypeof(c) = '%s'\n", c, typeof(c)) |
| 32 |
print "Test value not found in regex" |
| 33 |
c = gensub(/q/, "x", "g", b) |
| 34 |
printf("b = @/%s/\ttypeof(b) = '%s'\n", b, typeof(b)) |
| 35 |
printf("c = \"%s\"\ttypeof(c) = '%s'\n", c, typeof(c)) |
| 36 |
|
| 37 |
print "Test gensub on numbers" |
| 38 |
a = b = 12345 |
| 39 |
c = gensub(/3/, "x", "g", a) |
| 40 |
printf("a = \"%s\"\ttypeof(a) = '%s'\n", a, typeof(a)) |
| 41 |
printf("b = \"%s\"\ttypeof(b) = '%s'\n", b, typeof(b)) |
| 42 |
printf("c = \"%s\"\ttypeof(c) = '%s'\n", c, typeof(c)) |
| 43 |
print "Test value not found in number" |
| 44 |
c = gensub(/9/, "x", "g", b) |
| 45 |
printf("b = \"%s\"\ttypeof(b) = '%s'\n", b, typeof(b)) |
| 46 |
printf("c = \"%s\"\ttypeof(c) = '%s'\n", c, typeof(c)) |
| 47 |
print typeof(c), c |
| 48 |
} |