Expr. regulares (parte 2)

Catalin Lungu lcatalin en siadv.com
Jue Feb 23 17:32:19 CET 2006


A por cierto se me escapa una barita.

    ex2 = re.compile("[^-.]")

    ex2 = re.compile("[^-\.]")

Pues creo que con esto asunto arreglado.

Un saludo,
Catalin

----- Original Message ----- 
From: "Catalin Lungu" <lcatalin en siadv.com>
To: "La lista de python en castellano" <python-es en aditel.org>
Sent: Thursday, February 23, 2006 4:45 PM
Subject: Re: [Python-es] Expr. regulares (parte 2)


Si que necesito usar regex. Tengo que comprobar que en una caja de texto no 
se pueda introducir mas que números reales. De todas formas voy mejorando.

def EsNumero(numero):
    ex1 = re.compile("^\-?\(?([0-9]*([\.|,]?[0-9]*))\)?$")
    ex2 = re.compile("[^-.]")
    return ex1.match(numero) and ex2.match(numero)

Seguro se me escapa algun caso.
Saludos,
Catalin





----- Original Message ----- 
From: "Jordi Funollet" <jordi.f en ati.es>
To: "La lista de python en castellano" <python-es en aditel.org>
Sent: Thursday, February 23, 2006 3:17 PM
Subject: Re: [Python-es] Expr. regulares (parte 2)


> Oye Catalin,
>
> Perdona si me paso de listo, pero a lo mejor no necesitas usar regex... 
> ¿te
> serviria algo asi?
>
>
>>>> def EsDouble (strNumber):
> ...    try:
> ...       olvida = float( strNumber.replace(',', '.') )
> ...       return True
> ...    except ValueError:
> ...       return False
> ...
>
>>>> tests = ['-12345,678', '+12345.678', '-12345,67xx']
>>>> [EsDouble(t) for t in tests]
> [True, True, False]
>
>
>
> -- 
> ##############################
> ### Jordi Funollet
> ### http://www.terraquis.net
> _______________________________________________
> Python-es mailing list
> Python-es en aditel.org
> http://listas.aditel.org/listinfo/python-es
_______________________________________________
Python-es mailing list
Python-es en aditel.org
http://listas.aditel.org/listinfo/python-es 




Más información sobre la lista de distribución Python-es