Skip to content

Instantly share code, notes, and snippets.

@Fhernd
Created April 26, 2018 12:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Fhernd/3cf26db3a66f6f0c975e455c2a121d33 to your computer and use it in GitHub Desktop.
Save Fhernd/3cf26db3a66f6f0c975e455c2a121d33 to your computer and use it in GitHub Desktop.
Tokenización de texto. OrtizOL.
import re
NOMBRE = r'(?P<NAME>[a-zA-Z_][a-zA-Z_0-9]*)'
NUMERO = r'(?P<NUM>\d+)'
SUMA = r'(?P<PLUS>\+)'
PRODUCTO = r'(?P<TIMES>\*)'
IGUAL = r'(?P<EQ>=)'
ESPACIO = r'(?P<WS>\s+)'
patrones = re.compile('|'.join([NOMBRE, NUMERO, SUMA, PRODUCTO, IGUAL, ESPACIO]))
scanner = patrones.scanner('variable = 19')
print(scanner.match())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment