Regular Expressions

 import re


s="Python is am awesome cat car cam dog and a snake 27  30"


# res=re.findall("Python",s) # Finds all the string which is a match

# res=re.findall("c.t",s)

# res=re.findall("ca.",s)

# res=re.search("Python",s) # searches and returns a an object

# res=re.match("Python",s)

# res=re.findall(r"\d+",s) # used regex for finding numbers

# res=re.findall("[0-9]",s) # numbers

# res=re.findall("^Py",s) # starts with

# res=re.findall("30$",s) #Ends with

# res=re.findall("[A-Z]|[0-9]",s) # '|' used for OR condition

# res=re.findall("[a-zA-Z]",s) # Multiple ranges

# res=re.findall("[^0-9]",s) # ^ used in the front to denote not a digit

res=re.findall("[0-9]",s)

print(res)


Comments

Popular posts from this blog

Requests and Urllib

Python Time Zones