Search string excluding longer string containing substring that contains string, not exclusively longer string
Finite automata to the rescue!

Let 


$\mathcal{A} = \Sigma^* \cdot \{A\} \cdot \Sigma^*$ and 
$\mathcal{B} = \Sigma^* \cdot \{B\} \cdot \Sigma^*$ 


be the regular languages that contain all strings with substring $A$ resp. $B$.

Note then that

$\qquad\displaystyle L = \overline{\mathcal{B}} \cdot \{A\} \cdot \overline{\mathcal{B}}
\ \cup\  
\mathcal{A} \cdot \mathcal{B} 
\ \cup\  
\mathcal{B} \cdot \mathcal{A}$

is the set of all strings you are looking for, and from basic closure properties of REG we know that it is regular as well.

Constructing a (minimal) DFA from the above description using standard constructions yields an effective method that may or may not be efficient.