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

print(strToSearch)

patFinder1 = re.compile(‘Aa1B’)

findPat1 = re.search(patFinder1,strToSearch)

print(findPat1.group()) # 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:
print(i)

splitFound = patFinder1.split(strToSearch)
print(splitFound)

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

One Response to “Regex Tutorial Video Pt 2”

  1. roman says:

    WELCOME MAN

Leave a Reply

Your email address will not be published.

Google+