Sunday, October 27, 2019

Python program to fetch all words starting with a in a given string.

Ans:

import re
str ='an apple a day keeps the doctor awaya'
result = re.findall(r'a[\w]*' , str)

for word in result:
    print(word)

Oupput:

C:\Python_WorkSpace\TestProject\venv\Scripts\python.exe 
C:/Python_WorkSpace/TestProject/regdemo2.py
an
apple
a
ay
awaya

No comments: