Multiple occurrence subvector search and conditional copy with cuda Thrust

I want to find a marker in the function and extract a bunch of data out with cuda thrust.

I have got a solution for substring search with - Multiple occurrence subvector search with cuda Thrust - Stack Overflow which is working fine for string search applications. Although, when I tried different methods for extracting the character after it, the process became very costly.

In nutshell, for an array of str = “aaaabaaaaaaaaaaabaaaaaaaaaabaaaa”, I need to find occurrences of substr = “ab”, and extract 4 characters after the the occurance of substr from str.