0
why this code is not working
import re q=input("") pattern=r"[a-z][A-Z]+" match = re.search(pattern,q) if match==match: print('Deja Vu') else: print("Unique")
8 Respuestas
+ 2
I don't know where you copied this code from or why did you thought it would work,i have no idea about regular expression but what is really "match== match"?lol!
also I tried printing match after entering some string ,value of match is None
Basically you are comparing None=None
+ 1
you can sort that regular xpresion like this [a-zA-Z]+
+ 1
I agree whit Abhay you must validate if match equals true
Something like this
if match:
# your code
+ 1
To add to the other issues pointed out already, your regex searches for a lower-case letter, followed by 1 or more upper-case letters. This is not what the task is asking for.
+ 1
Abhay I copied my code from code coach
+ 1
The issue with your regex now is that it will match any string of letters, upper or lower-case, and there is no requirement for those letters to be the same.
If you are not fairly fluent in regex, then this is a tricky one to do. You need a capture group to capture a letter, then you need to use back-reference to try to match the same letter as you had in the capture group later on. It is hard to describe without just showing you the answer, and I always recommend learning things by yourself.
If you do want to learn regex more deeply, I would recommend Automate The Boring Stuff as it has a great tutorial on regex. https://automatetheboringstuff.com/2e/chapter7/
+ 1
https://code.sololearn.com/cSBPTG9PnsuI/?ref=app
use that
0
Russ ,Emanuel Maliaño,Abhay
import re
q=input("")
pattern=r"[a-zA-Z]+"
match = re.search(pattern,q)
if match==True:
print('Deja Vu')
else:
print("Unique")
still this code is not working