User input for a regular expressions string | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

User input for a regular expressions string

Can you use user input as a regular expression string. For example: words = r"spamspamspam" message = r input() if re. search(words, message): print("match") All Google results say to use 'raw_input()' but that's in Python 2 I want an easy way to test if there is ANY match whatsoever between a string and input. (So like testing a password for numbers and other symbols etc)

8th Mar 2020, 3:31 PM
Clueless Coder
Clueless Coder - avatar
4 Answers
8th Mar 2020, 4:26 PM
Oma Falk
Oma Falk - avatar
+ 4
it is simply message =input()
8th Mar 2020, 4:01 PM
Oma Falk
Oma Falk - avatar
8th Mar 2020, 4:07 PM
Clueless Coder
Clueless Coder - avatar
0
It's already a "raw" input.... try: print(input())... now enter something like ....hello\n \" \' world. It will output:- hello\n \" \' world......no escaping is done.
8th Mar 2020, 4:33 PM
rodwynnejones
rodwynnejones - avatar