Welcome Guest Search | Active Topics | Log In | Register

Regular expression capture
#1 Posted : Saturday, June 18, 2016 9:18:45 PM(UTC)
Rank: Newbie

Groups: Registered
Joined: 6/18/2016(UTC)
Posts: 1
Location: Maryland

Thanks: 0 times
Was thanked: 0 time(s) in 0 post(s)
The regular expression capture following a greedy expression does not always work right. This script

local i,j;
local rr;
local x = "ab12cde345fg";

rr = regexp("(\\d+)\\D+(\\d+)").capture(x);
        print("["+i+"] ");
else print("no match");

will produce the following output with the missing second capture

[0] 12cde345
[1] 12

If these two lines in sqstdrex.cpp

if(node->type != OP_NOCAPEXPR && node->right == exp->_currsubexp) {
    capture = exp->_currsubexp;

are replaced by these two lines

if(node->type != OP_NOCAPEXPR){
    capture = node->right;

then thing seem to work in all cases I could think of to test. Maybe this is not perfect, but it seems to work. The
output is now

[0] 12cde345
[1] 12
[2] 345

#2 Posted : Sunday, June 19, 2016 3:14:25 PM(UTC)
Rank: Advanced Member

Groups: Registered, Administrators
Joined: 6/11/2005(UTC)
Posts: 1,062

Thanks: 0 times
Was thanked: 80 time(s) in 62 post(s)
mmh, that looks like a bug. I'll investigate.

thank you
Follow me on Twitter @squirrellang
Users browsing this topic
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Clean Slate theme by Jaben Cargman (Tiny Gecko)
Powered by YAF 1.9.4 | YAF © 2003-2010, Yet Another Forum.NET
This page was generated in 0.758 seconds.