Untitled

 avatar
unknown
plain_text
a year ago
844 B
7
Indexable
1. Demonstrate usage of basic regular expression.
import re
print("--MENU--")
print("1.Use of ^ caret")
print("2.Use of $ dollar")
print("3.Use of * asteric")
print("4.Use of \ backslash")
print("5.Exit")
while True:
 i=int(input("Enter Your Choice:"))
 if(i==1):
 s=input("Enter a String:")
 x=re.findall("^The",s)
 if(x):
 print("Yes, the string-",s,"starts with The")
 else:
 print("No, the string-",s,"doesn't starts with The")
 elif i==2:
 s=input("Enter a String:")
 x=re.findall("Spain$",s)
 if(x):
 print("Yes, the string-",s,"ends with Spain")
 else:
 print("No, the string-",s,"doesn't ends with Spain")
 elif i==3:
 s=input("Enter a String:")
 x=re.findall("ai*",s)
 print(x)
 elif i==4:
 s=input("Enter a string:")
 x=re.findall("\d",s)
 print(x)
 elif i==5:
 break
 else:
 print("Invalid Choice")
Editor is loading...
Leave a Comment