Six strings that are for some reason important A -> a b c a b c B -> a b a b c a C -> a b c D -> b c a E -> b c a b F -> b c b a Those strings could potentially be very long. I want to find every occurrence of every of them is a potentially very long string Such as: b a b c a b a b c a b c x b c a b k a b a b c b a c b C appears between input positions 1 and 3 D appears between input positions 2 and 4 E appears between input positions 2 and 5 C appears between input positions 6 and 8 B appears between input positions 4 and 9 D appears between input positions 7 and 9 E appears between input positions 7 and 10 A appears between input positions 6 and 11 C appears between input positions 9 and 11 D appears between input positions 13 and 15 E appears between input positions 13 and 16 C appears between input positions 20 and 22 F appears between input positions 21 and 24 Verifying: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 b a b c a b a b c a b c x b c a b k a b a b c b a c b C appears between input positions 1 and 3 C -> a b c 1 2 3 a b c D appears between input positions 2 and 4 D -> b c a 2 3 4 b c a E appears between input positions 2 and 5 E -> b c a b 2 3 4 5 b c a b C appears between input positions 6 and 8 C -> a b c 6 7 8 a b c B appears between input positions 4 and 9 B -> a b a b c a 4 5 6 7 8 9 a b a b c a D appears between input positions 7 and 9 D -> b c a 7 8 9 b c a E appears between input positions 7 and 10 E -> b c a b 7 8 9 10 b c a b A appears between input positions 6 and 11 A -> a b c a b c 6 7 8 9 10 11 a b c a b c C appears between input positions 9 and 11 C -> a b c 9 10 11 a b c D appears between input positions 13 and 15 D -> b c a 13 14 15 b c a E appears between input positions 13 and 16 E -> b c a b 13 14 15 16 b c a b C appears between input positions 20 and 22 C -> a b c 20 21 22 a b c F appears between input positions 21 and 24 F -> b c b a 21 22 23 24 b c b a