YetAnotherForum
Welcome Guest Search | Active Topics | Log In | Register

Regular expression capture
robertjensen
#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

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

rr = regexp("(\\d+)\\D+(\\d+)").capture(x);
if(rr.len()){
    for(i=0;i<rr.len();i++){
        print("["+i+"] ");
        for(j=rr[i].begin;j<rr[i].end;j++){
            print(x[j].tochar());
        }
        print("\n");
    }
}
else print("no match");


will produce the following output with the missing second capture

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

If these two lines in sqstdrex.cpp

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

are replaced by these two lines

Code:
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


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

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

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

thank you
Alberto
Follow me on Twitter @squirrellang
Users browsing this topic
Guest
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.082 seconds.