Hi. I recently tried out gsub and figuring how it works, and I ran into a problem. I have a script like this
01 | local charmap = { |
02 | [ "k" ] = 'x' , |
03 | [ "kh" ] = 'x' , |
04 | [ "c" ] = 'k' , |
05 | [ "c?" ] = 'k' , |
06 | [ "c!" ] = 'k' , |
07 | [ "ch" ] = 'k' , |
08 | [ "cq" ] = 'k' , |
09 | [ "t" ] = 'c' , |
10 | [ "tr" ] = 'c' , |
11 | [ "c" ] = 'c' , |
12 | [ "ch" ] = 'c' , |
13 | [ "d" ] = 'z' , |
14 | [ "g" ] = 'z' , |
15 | [ "gi" ] = 'z' , |
but instead of printing "tieq", it prints "tieqw" (look at the character map for reference). Please fix it for me. Thanks in advance.
When I tested, it printed what it was supposed to: wieqz.
The first letter, t
was matched and replaced with w
.
The third and fourth letters, n
and g
were matched and replaced with q
.
The third letter, n
, was matched again and "replaced" with z
This is the product of gsub matching two different overlapping patterns.