Recording the history of Nellore

Uncategorized

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)

Leave a Reply

Discover more from Nellorean

Subscribe now to keep reading and get access to the full archive.

Continue reading