Imagine I have a set of strings, say:
#1: "A-B-B-C-C"
#2: "A-A-A-A-A-A-A"
#3: "B-B-B-C-A-A"
Now I want to check whether certain patterns occur in the first, middle, or last third in the sequence. Hence, I want to be able to formulate a rule of the kind:
Match the string if, and only if,
marker X occurs in the first/middle/last third of the string
For example, I may want to match strings which have an A
in the first third. The considering the sequences above I would match #1
and #2
. I could also want to match strings which have an A
in the last third. This would match #2
and #3
.
How can I write a generic code/regex pattern that can take various rules of this kind as input and then match the appropriate subsequences?