brainpy.tools.codes.get_identifiers
brainpy.tools.codes.get_identifiers#
- brainpy.tools.codes.get_identifiers(expr, include_numbers=False)[source]#
Return all the identifiers in a given string
expr
, that is everything that matches a programming language variable like expression, which is here implemented as the regexp\b[A-Za-z_][A-Za-z0-9_]*\b
.- Parameters
- Returns
identifiers – A set of all the identifiers (and, optionally, numbers) in expr.
- Return type
Examples
>>> expr = '3-a*_b+c5+8+f(A - .3e-10, tau_2)*17' >>> ids = get_identifiers(expr) >>> print(sorted(list(ids))) ['A', '_b', 'a', 'c5', 'f', 'tau_2'] >>> ids = get_identifiers(expr, include_numbers=True) >>> print(sorted(list(ids))) ['.3e-10', '17', '3', '8', 'A', '_b', 'a', 'c5', 'f', 'tau_2']