Python Exercise13

#regular expressions
import re

txt=”You can call me on 9988888888. My ATM pin is 1234 . You are good”
#find all occurances of “ATM”
words=re.findall(“ATM”,txt)
print(“Occurances of ATM : “,words)

#find if the string begins with “You”
words=re.findall(“^You”,txt)
print(words)

#find if the string ends with “You”
words=re.findall(“You$”,txt)
print(words)

#find all digits in the string”
words=re.findall(“d”,txt)
print(words)

#find one or more digits”
words=re.findall(“d+”,txt)
print(words)

#find ATM pin in the string”
words=re.findall(“dddd”,txt)
print(“ATM Pin”,words)

#find ATM pins in the string”
words=re.findall(“sdddds”,txt)
print(words)

#find ATM pins in the string”
words=re.findall(“sd{4}s”,txt)
print(words)

#find ATM pins in the string”
words=re.findall(r”bd{4}b”,txt)
print(words)

#find all ATM pin in the string and replace with ****
pin=re.sub(r”bd{4}b”,”****”,txt)
print(“Pin: “,pin)

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s