import re text = "a/NNP b/NNG c/NP d/NNP e/PNG" words = re.compile(r'\w+/(?:NNP|NNG)\b')print(re.findall(words,text))
Standard input is empty
['a/NNP', 'b/NNG', 'd/NNP']
The brand new service which powers Ideone!
Widget for compiling and running the source code in a web browser!