Skip to content

Instantly share code, notes, and snippets.

@elPytel
Created February 3, 2023 14:36
Show Gist options
  • Save elPytel/0743fd4765aeffc595cc5a4a62c1167b to your computer and use it in GitHub Desktop.
Save elPytel/0743fd4765aeffc595cc5a4a62c1167b to your computer and use it in GitHub Desktop.
s/[Aa]re\s[Yy]ou\s\(.*\)?/Indeed, I am \1./
# 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