import re regex = r"[^\s@]+@(?:[^][\s@]+|\[[^][]*])"s = "k1@v1 k2@[v1 v2 v3] k3@v1" matches = re.findall(regex, s)print(matches)
Standard input is empty
['k1@v1', 'k2@[v1 v2 v3]', 'k3@v1']
The brand new service which powers Ideone!
Widget for compiling and running the source code in a web browser!