Jan-21-2024, 06:22 PM
Example using re
import re phrase = "I'm selling fruits and vegetables from France" for match in re.finditer(r"([Ff]r\S*)", phrase): print(match)
Output:<re.Match object; span=(12, 18), match='fruits'>
<re.Match object; span=(34, 38), match='from'>
<re.Match object; span=(39, 45), match='France'>
If you only want the words.import re phrase = "I'm selling fruits and vegetables from France" print(re.findall(r"([Ff]r\S*)", phrase))
Output:['fruits', 'from', 'France']