import re pattern = r"\w+|[^\w \t]" text = "constructor SquareGame new(){\nlet square=square;\n}" print ( re.findall(pattern, text) )
Standard input is empty
['constructor', 'SquareGame', 'new', '(', ')', '{', '\n', 'let', 'square', '=', 'square', ';', '\n', '}']