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.
我对正则表达式很陌生,我想知道如何转换表达式,例如
$a * ($aa - $b)
进入
[a] * ([aa] - [b])
我正在使用 Python 的 re. 非常感谢!
>>> import re >>> strs = '$a * ($aa - $b)' >>> re.sub(r'\$(\w+)', r'[\1]', strs) '[a] * ([aa] - [b])'