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")

25th Jun 2020, 5:48 PM
Somil Khandelwal
8 Answers
+ 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
25th Jun 2020, 5:59 PM
Abhay
Abhay - avatar
+ 1
you can sort that regular xpresion like this [a-zA-Z]+
25th Jun 2020, 6:16 PM
Emanuel Maliaño
Emanuel Maliaño - avatar
+ 1
I agree whit Abhay you must validate if match equals true Something like this if match: # your code
25th Jun 2020, 6:20 PM
Emanuel Maliaño
Emanuel Maliaño - avatar
+ 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.
25th Jun 2020, 6:25 PM
Russ
Russ - avatar
+ 1
Abhay I copied my code from code coach
26th Jun 2020, 4:26 AM
Somil Khandelwal
+ 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/
26th Jun 2020, 8:29 AM
Russ
Russ - avatar
+ 1
https://code.sololearn.com/cSBPTG9PnsuI/?ref=app use that
20th Oct 2020, 6:29 AM
ă‚€ăƒ‡ăƒȘă‚»{非掻性}
ă‚€ăƒ‡ăƒȘă‚»{非掻性} - avatar
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
26th Jun 2020, 4:27 AM
Somil Khandelwal