There are a long list of strings $s$ and two lists of substrings $s1$ and $s2$. I want to take all elements of $s$ which contain a substring from $s2$ and such that before it on no more than $n$ places there is a string containing a substring from $s1$. For example, if
s={"a","b1","c","b2","a","c","b3"};
s1={"a"} ;
s2={"b"};
n=2;
the result should be {"b1","b3"}
because two previous to "b2"
elements don't contain substring "a"
.
It can be done with the help of Position
, creating and comparing two lists of elements positions with fragments from $s1$ and $s2$. Is there a more direct way without creating additional lists?