1. The match_all function

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.

new topic     » topic index » view message » categorize

2. Re: The match_all function

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

new topic     » goto parent     » topic index » view message » categorize

3. Re: The match_all function

dr_can said...

Inspired by Pete's Rosetta Code triumph

Glad someone is!

dr_can said...

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().

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu