1. The match_all function
- Posted by dr_can Jan 18, 2022
- 531 views
Inspired by Pete's Rosetta Code triumph, I have been looking at various Euphoria entries. One is entitled: Count occurrences of a sub-string. The Euphoria example was probably written before match_all was added, but if you convert the entry to this:
?match_all("th","the three truths") ?match_all("abab","ababababab")
what answers should you get?
I think 3 and 4, respectively, but match_all yields 3 and 2.
The code in search.e doesn't allow for any form of textual overlap, as in the chosen illustration. If intended then I think the reasons should be explicit, but they are not at present.
2. Re: The match_all function
- Posted by ChrisB (moderator) Jan 18, 2022
- 535 views
Hi
Then IMHO, th code in search.e is wrong. There should at the very least be an option to search overlaps, or not. There are obviously more ababs there. Looks like the search has started off at the end of the last find, instead of just incrementing the next search one character on from the beginning of the last match.
Cheers
Chris
3. Re: The match_all function
- Posted by petelomax Jan 18, 2022
- 513 views
Inspired by Pete's Rosetta Code triumph
Glad someone is!
I think 3 and 4, respectively, but match_all yields 3 and 2.
Well that confused me, until I realised you meant length(). Anyway, FYI, this is what Phix can do:
?match_all("th","the three truths") -- {1,5,14} (length 3) ?match_all("abab","ababababab") -- {1,5} (length 2) ?match_all("abab","ababababab",overlap:=true) -- {1,3,5,7} (length 4)
See here for the Phix version of match_all().