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-2=b (c-d)=3
输出:
- ,=, (, -, ), =
这不起作用:
re.finditer(r'[=+/-()]*', text)
您re需要使用反斜杠转义某些字符。(+, -, (,)在 中具有特殊含义re)。
re
+
-
(
)
无论如何,为此你不需要re:
(c for c in s if c in '+-/*()_')