Rotate your phone or change to desktop for better experience

Rotate your phone or change to desktop for better experience

1. Demonstrate usage of basic regular expression

 import re

txt = "The rain in Spain"

x = re.search("^The.*Spain$", txt)

if x:

print("YES! We have a match!")

else:

print("No match")

txt = "The rain in Spain"

x = re.findall("ai", txt)

print(x)

txt = "The rain in Spain"

x = re.split("\s", txt)

print(x)

txt = "The rain in Spain"

x = re.sub("\s", "9", txt)

print(x)

Post a Comment

0 Comments