get_identifiers function

(Shortest import: from brian2.utils.stringtools import get_identifiers)

brian2.utils.stringtools.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.


expr : str

The string to analyze

include_numbers : bool, optional

Whether to include number literals in the output. Defaults to False.


identifiers : set

A set of all the identifiers (and, optionally, numbers) in expr.


>>> 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']