Skip to content

Instantly share code, notes, and snippets.

@SamuelM333
Created July 12, 2016 15:11
Show Gist options
  • Save SamuelM333/fec53e08bc13ce3ac13014ddac53fddc to your computer and use it in GitHub Desktop.
Save SamuelM333/fec53e08bc13ce3ac13014ddac53fddc to your computer and use it in GitHub Desktop.
Funcion recursiva que valida la entrada mediante expresiones regulares (Python 2)
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