Il giorno 11 settembre 2013 15:28, Daniele Zambelli < daniele.zambe...@gmail.com> ha scritto:
> > Il dubbio che ho è che la faccenda non sia molto efficiente dato che ci > possono essere molte definizioni. E, se non sbaglio, si avvia un meccanismo > di backtracking. Per questo motivo avevo cercato di cambiare il gruppo come > nello spezzone seguente: > > re1 = re.compile(r'''^\\begin\{description\}\n > > \\item\[\{([^\}]+)\}\]\s\\leavevmode\n > > (.*^(\n\\end\{description\}))\n\\end\{description\}$''', > re.M | re.S | re.X) > > > Ma così non funziona. C'è un modo per evitare il backtracking? > non credo che ci sia modo di evitare una intera stringa, che è quello che cercavi di fare tu, bensì al più un solo carattere Dalla documentazione: Characters that are not within a range can be matched by *complementing*the set. If the first character of the set is '^', all the characters that are *not* in the set will be matched. For example, [^5] will match any character except '5', and [^^] will match any character except '^'. ^ has no special meaning if it’s not the first character in the set. ... non si parla di sequenze ma solo di singoli caratteri direi che non c'è scampo all'andare di non-greedy come effettivamente hai fatto Se non ricordo male questa limitazione è intrinseca e ha a che fare con il vincolo delle espressioni regolari di poter essere implementate con automi a stati finiti gradite altre opinioni, Marco
_______________________________________________ Python mailing list Python@lists.python.it http://lists.python.it/mailman/listinfo/python