How can I carry out overlap string match
Show older comments
Hi,
I have a string as such:
seq1 = 'QEAFEISKXXXXXXX'
I want to find all occurrences of two Xs separated by a single character (including X). By inspection, there are seven Xs side-by-side in the sequence so the answer i am looking for in terms of indices is: 9 10 11 12 13
I have used regexp as follows:
seq1 = 'QEAFEISKXXXXXXX';
seq2 = 'X.X'; % Dot indicates any character to match with
regexp(seq1, seq2)
The answer i get is: 9 12
How can i modify the code to get every occurrence?
Thanks.
Accepted Answer
More Answers (1)
Andrei Bobrov
on 4 Oct 2017
strfind('QEAFEISKXXXXXXX','XX')
2 Comments
Abel Chandra
on 4 Oct 2017
Andrei Bobrov
on 4 Oct 2017
exotics:
ii = strfind('QEAFEIXKXXXXXXX','X');
out = ii(any(bsxfun(@minus,ii(:),ii(:)') == -2,2));
Categories
Find more on Characters and Strings in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!