In a construction like
string.scan(regex){...}
or
string.gsub(regex){...}
how can check if the match for a loop cycle is adjacent to the previous one in the original string? For example, in
"abaabcaaab".scan(/a+b/){|match|
...
continued = ...
...
}
there will be three matches "ab"
, "aab"
, and "aaab"
. During each cycle, I want them to have the variable continued
to be false
, true
, and false
respectively because "ab"
is the first match cycle, "aab"
is adjacent to it, and "c"
interrupts before the next match "aaab"
.
"ab" #=> continued = false
"aab" #=> continued = true
"aaab" #=> continued = false
Is there an anchor in origuruma that refers to the end of the previous matching position? If so, that may be used in the regex. If not, I probably need to use things like MatchData#offset
. and do some calculation in the loop.
By the way, what is \G
in origuruma regex? I had the impression that it might be the anchor that I want, but I am not sure what it is.