First, note that Lua's string patterns are not full regular expressions. They are more limited and less powerful, but usually sufficient (as in this case).
Why not a far simpler replacement such as the following?
local s1 = [[
<integer>3</integer>
<integer>3.12</integer>
<integer>-1.00</integer>
<integer>-1.99</integer>
<float>3.14</float>
]]
local s2 = s1:gsub('(<integer>%-?%d+)%.%d+','%1')
print(s2)
--> <integer>3</integer>
--> <integer>3</integer>
--> <integer>-1</integer>
--> <integer>-1</integer>
--> <float>3.14</float>
This finds:
- the text
<integer>
, - optionally followed by a literal hyphen (
%-?
) - followed by one or more digit characters (
%d+
) - followed by a literal period (
%.
) - followed by one or more digit characters (
%d+
)
and replaces it with the first capture (the contents of 1-3, above).
Note that this will not work if you can have floats without a leading digit (e.g. <integer>.99</integer>
) or scientific notation (e.g. <integer>1.34e7</integer>
).