La cosa migliore è cambiare il file...così l'unica soluzione potrebbe essere questa, ma credo che sia , molto più lenta rispetto a cambiare il file.

Diciamo che hai una stringa così fatta:

$str = blablablaABCDbbbaaaABEF_BAFEvvvvvEEBB

Dove le parti in grassetto sono i tuoi alg()
Se non ho capito male tu hai un alg(var) ed una lista di alg(*)
es:
$alg = ABEF
$algs = {ABCD, ABEF, EEBB, BAFE, ABEF} //Con l'odine che può differire da quello della stringa

In questo caso tu vorresti riprendere "bbbaaa".
Quindi dovresti fare:

Codice PHP:
$end strpos($str$alg0);
$start 0;
$key = -1;
foreach(
$algs as $k => $a){
    if(
$a == $alg) continue;
    
$tmp strpos($str$a0);
    if(
$tmp  !== FALSE && $tmp $end && $tmp >= $start ) {
        
$start $tmp;
        
$key $k;
    }
}


if(
$key != -1){
   
$start += strlen($algs[$key]);
}

echo 
substr($str$start$end-$start); 
Non l'ho testato, ma credo che forse dovresti rivedere gli indici $start ed $end per i casi particolari (tipo se alg(var) è il primo e non c'è la parte a sx).

Cmq, ti consiglio di rivedere la struttura della stringa...