I’ll be implementing the RegExp in JavaScript.
I think the best way to explain this is with an example. If the search string is
'abc'
and the haystack is
'auaisdgbbhbcsccddciubbffs'
the pattern needs to hit:
'[a]uaisdg[b]bhbcsc[c]ddciubbffs' and
'au[a]isdgb[b]hbcsc[c]ddciubbffs'
and return the positions of these characters…
Can Regex even be made to do such a thing?
Given that we don’t know the programming language you are using, it’s impossible to provide a definitive answer at this point.
That said, I am not aware of any regex construct which would allow this sort of match.
If I understand correctly, you want to find an ‘a’ which, for example, is followed by a ‘b’ six characters later. Then, because ‘b’ occured six characters after ‘a’, you want to find a ‘c’ six characters after ‘b’. Essentially, you want backreferences, but you want to match only the length of the backreference and not the actual text. I don’t think this is possible with regular expressions.
It’s possible that some regex implementation out there has an uncommon construct which allows this, so knowing your platform would help.
UPDATE
Javascript has one of the least powerful regex implementations out there. I don’t think you are going to be able to do this with pure regexp. You’ll need to write some additional code (and I’d honestly recommend a “code only” approach for your simple example).