Regex Tutorial Video Pt 2

Python How ToIn this tutorial, I continue teaching you how to use Regular Expressions. I specifically go over the numerous functions available in the Python programming language that you can use for searches.

I will explain how to:

  • Grab text from text files
  • Create Regular Expressions in Python
  • Search through strings or files for information
  • Manipulate the information, once you retrieve it

If you have any questions, leave them in the comment section below. Enjoy the video

The Code From the Video

f = open(‘randomcharacters.txt’)

strToSearch =””

for line in f:
strToSearch += line


patFinder1 = re.compile(‘Aa1B’)

findPat1 =,strToSearch)

print( # Returns the entire first match
print(findPat1.start()) # Returns the location of the first character that matches
print(findPat1.end()) # Returns the location of the last character that matches
print(findPat1.span()) # Returns a tuple with the starting and ending indexes

findPat1 = re.findall(patFinder1,strToSearch)

findPat2 = re.finditer(patFinder1,strToSearch)

for i in findPat1:

splitFound = patFinder1.split(strToSearch)

subFound = patFinder1.sub(‘Real Text ‘,strToSearch)

One Response to “Regex Tutorial Video Pt 2”

  1. roman says:


Leave a Reply

Your email address will not be published.