import re
keyword_pattern='love|love India'
Sentence=I love India
Match=re.finditer(pattern, sentence)
Example Keywords=['love', 'love India', 'pakistan'] Sentence= 'I love India'
Output I need: ['love', 'love India']
Output I am getting: [love]
import re
keyword_pattern='love|love India'
Sentence=I love India
Match=re.finditer(pattern, sentence)
Example Keywords=['love', 'love India', 'pakistan'] Sentence= 'I love India'
Output I need: ['love', 'love India']
Output I am getting: [love]
The docs state that
For the sake of convenience, we can also use
re.findall, which basically does the same as[el.group() for el in re.finditer(...)], but has the same problem:But since your have nicely separated groups of patterns, just loop over them:
yields for
matches: