Created
July 12, 2016 15:11
-
-
Save SamuelM333/fec53e08bc13ce3ac13014ddac53fddc to your computer and use it in GitHub Desktop.
Funcion recursiva que valida la entrada mediante expresiones regulares (Python 2)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
def validar_entrada(match, text, error): | |
"""Funcion recursiva que valida la entrada mediante expresiones regulares. | |
Recibe: | |
match: Expresion regular a buscar | |
text: Texto a mostrar en el input | |
error: Texto a mostrar cuando la expresion regular no encuentra nada | |
Retorna: | |
String con el texto que encontro la expresion regular. Si hubo un error, la funcion se vuelve a llamar | |
""" | |
n = re.match(match, raw_input(text).lower()) | |
if n is None: | |
print(error) | |
return validar_entrada(match, text, error) | |
else: | |
return n.group(0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment