Created
February 3, 2023 14:36
-
-
Save elPytel/0743fd4765aeffc595cc5a4a62c1167b to your computer and use it in GitHub Desktop.
s/[Aa]re\s[Yy]ou\s\(.*\)?/Indeed, I am \1./
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
# By Pytel & Copilot | |
""" | |
Tento program načte vstup od uživatele a upraví pomocí regulárního výrazu. | |
Vzorový vstup: | |
"Are you sentient?" | |
Vzorový výstup: | |
"Indeed, I am sentient." | |
Vzorový vstup: | |
"are you capable of intelligence?" | |
Vzorový výstup: | |
"Indeed, I am capable of intelligence." | |
Regulární výraz: | |
s/[Aa]re\s[Yy]ou\s\(.*\)?/Indeed, I am \1./ | |
""" | |
import re | |
def main(): | |
""" Main function. """ | |
print("This program will change your input with regex.") | |
print("Enter 'q' to quit.") | |
while True: | |
text = input("Enter your text: ") | |
if text == 'q': | |
break | |
text = re.sub(r'[Aa]re\s[Yy]ou\s(.*)\?', r'Indeed, I am \1.', text) | |
print(text) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment