Created
May 30, 2016 16:13
-
-
Save lborg019/f11701a0d0961d141f5909c824a24e4c to your computer and use it in GitHub Desktop.
Boilerplate regular expression parser for python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
# file to be read (replace "list.txt" with your file name | |
infile = open("list.txt", "r") | |
# file to write to | |
outfile = open("result.txt", "w") | |
# traverse the file | |
for line in infile: | |
match = re.search('', line) # match our regular expression | |
''' | |
at re.search('', line), replace '' | |
for your regular expression | |
http://pythex.org | |
http://regexr.com | |
for more information on regex | |
''' | |
if match is None: # no matches found | |
continue | |
else: # at least one match found | |
target = match.group(0) | |
''' | |
at this point, our match is in our target var | |
this is the perfect spot to massage our data | |
by either snipping, appending, prepending or | |
whatever | |
''' | |
print(target) # print values caught | |
outfile.write(target+"\n") # write them to file | |
# close both files | |
outfile.close() | |
infile.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment