Skip to main content

regular expression in Python

 





import re

my = '''the quick brown fox jumps over the lazy dog
Don't worry this is only  a string or another else
Some data: 242033$#
Name: Aakash
Phone No: 7652906544
234-25346
class: BCA 2nd Year
Address: #401/3 Mauli jagran Chandigarh
email: aakash3640@gmail.com '''
# s = input("Enter for Search: ")
# f = re.compile(r'\AName')
# f = re.compile(r'Name\A')
# f = re.compile(r'\bName')
# f = re.compile(r'Name\b')
f = re.compile(r'\d{3}-\d{5}')
# mat = f.findall(my)
# mat = f.search(my)
# mat = f.split(my)
mat = f.finditer(my)
# for m in mat:
    # print(m)


e = ''' +917652906544
5498796545
4563289745
+91763452906544
+917643906544
+913552906546
+915465
+911482465352
+917889258834
+916598324521 '''
r= re.compile(r'\b91\d{10}')
s = r.finditer(e)
for i in s:
    print(i)


Comments