import re text = r'$\$x + \$y = 5$ and $3$'print re.findall(r'(?<=\$)([^$\\]*(?:\\.[^$\\]*)*)(?=\$)', text)
Standard input is empty
['\\$x + \\$y = 5', ' and ', '3']
The brand new service which powers Ideone!
Widget for compiling and running the source code in a web browser!