#Importing Regular Expressions Module
import re
# **Meta Characters**
# [] A set of characters
# \ Signals a special sequence (can also be used to escape special characters)
# . Any character (except newline character)
# ^ Starts with
# $ Ends with
# * Zero or more occurrences
# + One or more occurrences
# {} Exactly the specified number of occurrences
# | Either or
# () Capture and group
# **Special Sequences**
# \A Returns a match if the specified characters are at the beginning of the string
# \b Returns a match where the specified characters are at the beginning or at the end of a word r"ain\b"
# \B Returns a match where the specified characters are present, but NOT at the beginning (or at the end) of a word
# \d Returns a match where the string contains digits (numbers from 0-9)
# \D Returns a match where the string DOES NOT contain digits
# \s Returns a match where the string contains a white space character
# \S Returns a match where the string DOES NOT contain a white space character
# \w Returns a match where the string contains any word characters (characters from a to Z, digits from 0-9, and the underscore _ character)
# \W Returns a match where the string DOES NOT contain any word characters
# \Z Returns a match if the specified characters are at the end of the string
mystr = '''Tata Limited
Dr. David Landsman, executive director
18, Grosvenor Place
London SW1X 7HSc
Phone: +44 (20) 7235 8281
Fax: +44 (20) 7235 8727
Email: tata@tata.co.uk
Website: www.europe.tata.com
Directions: View map
Tata Sons, North America
1700 North Moore St, Suite 1520
Arlington, VA 22209-1911
USA
Phone: +1 (703) 243 9787
Fax: +1 (703) 243 9791
66-66
455-4545
Email: northamerica@tata.com
Website: www.northamerica.tata.com
Directions: View map fass
harry bhai lekin
bahut hi badia aadmi haiaiinaiiiiiiiiiiii'''
# Functions To Search Any Word In The Given String - findall,search,split,sub,finditer
# If You Want To Run Any Code In The Software Please Uncomment It.
# Compiling Using Compile Function In re
# pattern = re.compile(r"North")
# pattern = re.compile(r".")
# pattern = re.compile(r"^Tata")
# pattern = re.compile(r"Tata$")
# pattern = re.compile(r"iii$")
# pattern = re.compile(r"ai*")
# pattern = re.compile(r"a*i*")
# pattern = re.compile(r"a+i+")
# pattern = re.compile(r"(ai)+")
# pattern = re.compile(r"(ai){2}")
# pattern = re.compile(r"(ai){2}|(t){1}")
# pattern = re.compile(r"\ATata")
# pattern = re.compile(r"Tata\b")
# pattern = re.compile(r"\BVA")
# pattern = re.compile(r"\d28")
# pattern = re.compile(r"\DWebsite")
# pattern = re.compile(r"\d{5}-\d{4}")
# a = pattern.findall(mystr)
# print(a)
# b = pattern.search(mystr)
# print(b)
# c = pattern.split(mystr)
# print(c)
# d = pattern.sub(mystr,mystr)
# print(d)
# e = pattern.finditer(mystr)
# print(e)
# for i in e:
# print(i)
# print(mystr[224:229])
#Task To Print The List Of All The Numbers Given In The String.
mystring = '''+918266272754
+919425266282
+919277272789
+917272828828
+918272672782'''
pattern = re.compile(r"[+]\d{12}")
matches = pattern.findall(mystring)
print(matches)
print(type(matches))
Comments
Post a Comment