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 - https://stackoverflow.com/questions/55999456/multiple-occurrence-subvector-search-with-cuda-thrust 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.