python how to extract operators from string

python, regex

Solution

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 '+-/*()_')

Problem

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) ```

Original source