¿Hay alguna manera de depurar una expresión regular en Python? Y no me refiero al proceso de tratar y tratando hasta que funcionan :)¿Cómo puedo depurar una expresión regular en python?
EDIT: aquí es cómo expresiones regulares se pueden probar en Perl:
use re 'debug';
my $str = "GET http://some-site.com HTTP/1.1";
if($str =~/get\s+(\S+)/i) {
print "MATCH:$1\n";
}
El código anterior produce la siguiente salida en mi computadora cuando corrió:
Compiling REx "get\s+(\S+)"
Final program:
1: EXACTF (3)
3: PLUS (5)
4: SPACE (0)
5: OPEN1 (7)
7: PLUS (9)
8: NSPACE (0)
9: CLOSE1 (11)
11: END (0)
stclass EXACTF minlen 5
Matching REx "get\s+(\S+)" against "GET http://some-site.com HTTP/1.1"
Matching stclass EXACTF against "GET http://some-site.com HTTP/1.1" (33 chars)
0 | 1:EXACTF (3)
3 | 3:PLUS(5)
SPACE can match 1 times out of 2147483647...
4 | 5: OPEN1(7)
4 | 7: PLUS(9)
NSPACE can match 20 times out of 2147483647...
24 | 9: CLOSE1(11)
24 | 11: END(0)
Match successful!
MATCH:http://some-site.com
Freeing REx: "get\s+(\S+)"
Seriamente: dar a SO su regex + muestra de datos? – annakata
Sin código de muestra, todo lo que podemos hacer es adivinar cuál es tu problema. –
No tengo un problema de expresiones regulares en este momento. Solo quiero saber cómo realizar la depuración. – Geo