0

First code using regular expressions. It doesn't match the digits. Any explanation

https://code.sololearn.com/cvly4BxMk6JN/?ref=app

8th Apr 2020, 10:57 AM
Justus
Justus - avatar
14 Respuestas
+ 2
Did you do as I said and put the hyphen character ("-") at the end of the character array on line 3?
8th Apr 2020, 11:50 AM
Russ
Russ - avatar
+ 1
Thanks very much.
8th Apr 2020, 11:53 AM
Justus
Justus - avatar
0
Not sure about you, but I got an error when I ran your code (using your default input). This was a problem I had before that confused me for some time! If you want to match a character within a range, you would use something like "[a-z]". The "-" is the symbol that notifies the parser that you are specifying a range. In your array of symbols, "-" is buried in the middle of them all and the parser thinks you are specifying a range, when you just actually want that character. Solution: put "-" at the end 😉
8th Apr 2020, 11:12 AM
Russ
Russ - avatar
0
Russ it still doesn't match the digits,
8th Apr 2020, 11:36 AM
Justus
Justus - avatar
0
?? It does for me. What input are you using?
8th Apr 2020, 11:37 AM
Russ
Russ - avatar
0
I don't know if the problem is with r"\d+"
8th Apr 2020, 11:37 AM
Justus
Justus - avatar
0
Default, it's suppose to output true, but it's false
8th Apr 2020, 11:38 AM
Justus
Justus - avatar
0
That part seems to be fine. Like I said, all inputs I try work for me. Can you give me an example of an input that you are trying that hasn't worked?
8th Apr 2020, 11:39 AM
Russ
Russ - avatar
0
https://code.sololearn.com/c41H5BJpXMxv/?ref=app Does this print False for you if you don't give any input?
8th Apr 2020, 11:41 AM
Russ
Russ - avatar
0
import re pword="Sololearn@8" pattern = r"[@#
amp;_-!?*/\%]" if len(pword) >5: if re.search(r"\d+-",pword): if re.search(pattern,pword): print("True") else: print("False") else: print("False") else: print("False") #Output False
8th Apr 2020, 11:42 AM
Justus
Justus - avatar
0
You have a "-" after your "\d+". That would be why it doesn't match a number in that example. But that isn't (edit: wasn't) there in the code you posted.
8th Apr 2020, 11:44 AM
Russ
Russ - avatar
0
😳. I don't see the difference, but the code you posted runs. Even after removing "-" mine does not
8th Apr 2020, 11:47 AM
Justus
Justus - avatar
0
In the 3th if you said find any numbers with a "-" at the next. It has to be r"\d+" that indicates only one or many numbers.
9th Apr 2020, 10:16 PM
Jonathan Alvarado
Jonathan Alvarado - avatar