Reputation: 1344
I am executing this.
print(re.findall(r'(<OR|<PP).*>', '<OR first><PP second><OR third>'))
Expected:
['<OR first>', '<PP second>', '<OR third>']
Actual:
['<OR']
Does any body know how I can achieve the expected?
Upvotes: 0
Views: 714
Reputation: 8413
import re
print(re.findall(r'(?:<OR|<PP)[^>]*>', '<OR first><PP second><OR third>'))
Note that
.*
matches greedily, so your pattern matches the whole stringUpvotes: 3