An archive of community.esquilo.io as of Saturday January 26, 2019.

# Regexp capture unexpected behavior

robertjensen

regexp capture returns the expected result in the first case below, but not in the second. Here is the code.

local i;
local rr;
local x = "ab12cd34de";

rr = regexp("(\\d\\d)(.+)(\\d\\d).").capture(x);
for(i=0;i<rr.len();i++){
print(rr[i].begin+" - "+rr[i].end+"\n");
}

print("-------------\n");

rr = regexp("(\\d\\d).+(\\d\\d).").capture(x);
for(i=0;i<rr.len();i++){
print(rr[i].begin+" - "+rr[i].end+"\n");
}

Here is the output

2 - 9
2 - 4
4 - 6
6 - 8
-------------
2 - 9
2 - 4
0 - 0

Why is the last capture 0-0 and not 6-8?

Scott_Shumate

It looks like its a bug in the core Squirrel library. I tried the stock Squirrel 3.0.7 and 3.1 RC1 on Linux and it gave me the same result. I too would expect 6-8 from your regex. We'll want to feed this upstream to the Squirrel folks.

-Scott