I want to extract operators like: +,-,/,*
and also (,),_
from the string
Eg.
a-2=b
(c-d)=3
output:
- ,=, (, -, ), =
This does not work:
re.finditer(r'[=+/-()]*', text)
Your re
needs to escape some of the characters with a backslash. (+
, -
, (
, )
have their special meanings in re
).
Anyway, for this you don't need re
:
(c for c in s if c in '+-/*()_')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With