Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
对不起,我是 python 新手。我正在尝试从表达式中提取变量,例如:
ABC=DEF=5 C=DF/10
我想提取 ABC、DEF、C、DF 等。
这适用于您给出的示例,对于更复杂的代码当然会失败。
>>> import re >>> text = '''ABC=DEF=5 C=DF/10''' >>> re.findall(r'[a-zA-Z_]\w*', text) ['ABC', 'DEF', 'C', 'DF']