Rotate your phone or change to desktop for better experience

Rotate your phone or change to desktop for better experience

2. Demonstrate use of advanced regular expressions for data validation.

 import re

str = "yes I said yes I will Yes."

res = re.sub("[yY]es","no", str)

print(res)

str = "Course location is London or Paris!"

res = re.search(r"location.*(London|Paris|Zurich|Strasbourg)",str)

if res:

 print(res.group())

line = "James;Miller;teacher;Perl"

line=re.split(";",line)

print(line)

t="A fat cat doesn't eat oat but a rat eats bats."

mo = re.findall("[force]at", t)

txt1 = re.findall('\S', t)

txt2 = re.findall('\W', t)

print(mo)

print(txt1)

print(txt2)

Post a Comment

0 Comments