I am trying to extract tokens from a string, such that these tokens meet certain conditions. In my particular case, I want to extract symbols such as +,=,-, etc.
I have created the following regex:
reg = re.compile(r"[\{\}\(\)\[\]\.,;\+\-\*\/\&\|<>=~]")
However, when I apply:
reg.findall('x += "hello + world"')
It also matches the + between quotes, so it outputs:
['+', '=', '+']
My expected output is:
['+', '=']
My question is, how do I achieve this? Is it even possible? I have been surfing on the internet, but only found how to match everything but double quotes, and the ones like that.