From 63a1bafaa0096bb1ee024e2e2bbb25b715a7cb6c Mon Sep 17 00:00:00 2001 From: Caleb Fontenot Date: Mon, 15 Jul 2019 12:40:44 -0500 Subject: [PATCH] modified: madlibs.py new file: regex.py --- madlibs.py | 21 +++++++++++++++++---- regex.py | 16 ++++++++++++++++ 2 files changed, 33 insertions(+), 4 deletions(-) create mode 100644 regex.py diff --git a/madlibs.py b/madlibs.py index f1434ed..2deed7b 100644 --- a/madlibs.py +++ b/madlibs.py @@ -45,7 +45,7 @@ if args.setup == True: if platform.system() == 'Linux': print('Linux master race! XD') # Introduce yourself -print (colored("<>", 'red'), '\n' "Built on July 13, 2019") +print (colored("<>", 'red'), '\n' "Project started on July 13, 2019") print("I pull txt files in the directory you place me in for stories!" '\n' '\n' "Run me with the --setup flag for instructions on setting a story up!" '\n') # Notify if verbose @@ -76,8 +76,21 @@ storyContent = f.readline() # Hacky shenanigans #selectedStoryName = storyName[story - 1] -# Print current story +# Print current story title print("Current story title is", '"'+storyName+'"') -re.findall( -print(storyContent) +# Alright, now onto the tricky part. We need to filter out all of the bracketed words in stories.txt, putting them into a list, replacing them with incremental strings. We also need to count how many there are for later. +# Pull all of the items with the <> brackets +filtered = re.findall(r'<.*?>', storyContent) +filteredReplaced = re.sub(r'<.*?>', storyContent) +# We got them! +print(filtered) +# Now we need to count them +replacedNumber = len(filtered) +print(replacedNumber) + + + + + + diff --git a/regex.py b/regex.py new file mode 100644 index 0000000..e483ab5 --- /dev/null +++ b/regex.py @@ -0,0 +1,16 @@ +# import re library +import re + +# Here's our string +lol = "Lol this is a string" +print(lol) + +# now let's filter out the word "string" +p = re.compile('string') + +filtered = p.match('string') + +print(filtered) + + +