I\'m trying to use python\'s regular expression to match a string with several words. For example, the string is \"These are oranges and apples and pears, but not pinapples
Try this:
>>> re.findall(r"\band\b|\bor\b|\bnot\b", "These are oranges and apples and pears, but not pinapples or ..") ['and', 'and', 'not', 'or']
a|b means match either a or b
\b represents a word boundary
re.findall(pattern, string) returns an array of all instances of pattern in string