Question: Is there a StringTools:-RegFilter function that does the opposite of the built-in `StringTools:-RegSplit`?

There are two opposing commands remove and select in Maple. According to the main help page, StringTools:-RegSplit effectively implements the removal (i.e., capturing substrings that does not match the given pattern), but as regards extracting the matching parts of the input string (e.g., this example from MatLab), where is the command to carry out the selection?
At present I can do something like 

use StringTools in RegFilter := (p::string, s::string) -> select[2](RegMatch, sprintf("^%s$", p), (op@NGrams)~(s, [`$`](Length(s)))) end:
RegFilter("a.++b", "aabbbaaabb");
 = 
 ["aab", "abb", "aab", "abb", "aabb", "abbb", "aaab", "aabb", 

   "aabbb", "aaabb", "abbbaaab", "aabbbaaab", "abbbaaabb", 

   "aabbbaaabb"]


Nevertheless, there exist at least two disadvantages to it.

This is essentially equivalent to letting the matcher keeps starting at the same position until no more new matches are found, while sometimes one may just need the matcher to continue the shortest-match testing at the character following the last matched substring after finding a match:

For instance, there should be three flags in “RegFilter("a.+?b", "aabbbaaabb", 'overlapped'=⁇);”: 
⒈“["aab", "aaab"]” (selection with no overlap), 
⒉“["aab", "abb", "aaab", "aab", "abb"]” ( with partial overlaps), and 
⒊“["aab", "aabb", "aabbb", "aabbbaaab", "aabbbaaabb", "abb", "abbb", "abbbaaab", "abbbaaabb", "aaab", "aaabb", "aab", "aabb", "abb"]” ( with full overlaps). 

Unfortunately, the RegFilter above can only handle the last mode.

Another disadvantage is its inefficiency. Considering the following regular expression which matchs email-like strings

sample := Import("https://github.com/mariomka/regex-benchmark/raw/optimized/input-text.txt"): # lengthy 
re := "[a-zA-Z_0-9\\.+-]+@[a-zA-Z_0-9\\.-]+\\.[a-zA-Z_0-9\\.-]+":
time[real]((remnants := StringTools:-RegSplit(re, sample)));
 = 
                             3.157

So Maple is capable of completing this removal within 4 seconds, yet if I execute the analogous

timelimit(60, time[real](RegFilter(re, sample))); 

Maple will end up running out of memory.

In view of these, where is the generic StringTools:-RegFilter functionality? Or can we reconstruct those matched cases from remnants and the original text?

Please Wait...