+ 2

How to put input into pattern of regex(plain string) ?

I want to have a search function(with regex) which will take input from user and search the input through a content(any text).

28th Oct 2020, 4:41 AM
Jyoti Prasad Boro
Jyoti Prasad Boro - avatar
2 Respostas
+ 7
You can take an input like "[0-9]" (do not enter the quotes !) and store it in a variable like "pattern". then use this variable in your regex call like: if re.search(pattern, password): ....
28th Oct 2020, 10:56 AM
Lothar
Lothar - avatar
+ 1
Lothar thanks man. I was wrong to think that pattern must be smthing like this: pattern = r"smthing" This is possible: pattern = input()
28th Oct 2020, 2:43 PM
Jyoti Prasad Boro
Jyoti Prasad Boro - avatar