This is just a few lines of really simple, understandable, reliable code that you could have written and rewritten 3 times in the amount of time it takes you to post and get a response to the RE version. (And, of course, with the RE version it won't be obvious what you are doing).
int examine(String s) {
int foundAt=-1;
for(int i=0;i<s.length;i++) {
char c=s.charAt(i); // something like that
if(c=='A') {
foundAt=i;
continue;
}
if(foundAt != -1) {
if(c == 'B' && i-foundAt < 5 || i-foundAt > 6)
return foundAt;
if(!String.isNumber(c)) // something like that
foundAt = -1; // Not a number before B, reset
}
}
return -1;
}
Okay, so it's slightly more than a few lines (but it is wrapped in a function call too), but modifying the behavior to do something tricky is more straight forward than modifying an RE where changes can easily incur unintended consequences, it should be trivial to read, and once the first few simple bugs are wiped out, it will be foolproof--something that seems to never be true of regular expressions.
So, isn't this about as short and readable as you are going to get?
n=examine(s);
Any "advantage" of shorter code is completely eliminated if replaced by an easy to read, reliable function call.
(I figure there is a good chance this is a homework question and this should NOT properly answer it if it is)