java - Find all occurrences of a divided substring in a string -
i'm trying solve little extraordinary problem. need find amount occurrences of substring in string if substring don't have in 1 piece.
example: input:adnndaend i'll seek find substring and.
occurrences:adnndaend
adnndaend
adnndaend
adnndaend
adnndaend
adnndaend
output:6 i've tried accomplish list of occurences using python re.findall:
re.findall('^.*a.*n.*d.*$', 'adnndaend') but returns list 1 item - whole string:
['adnndaend'] so you, please, tell me, what's wrong regex or show me improve solution? ideally in python or java, i'm not familiar other languages.
you combinations of using amount of times a, n , d appear:
from itertools import combinations def sub_s(st,word): all_s = (x x in st if x in word) homecoming len([x x in (combinations(all_s, len(word))) if "".join(x) == word] ) java python regex algorithm
No comments:
Post a Comment