0
First code using regular expressions. It doesn't match the digits. Any explanation
13 Answers
+ 2
Did you do as I said and put the hyphen character ("-") at the end of the character array on line 3?
+ 1
Thanks very much.
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 đ
0
Russ it still doesn't match the digits,
0
?? It does for me.
What input are you using?
0
I don't know if the problem is with r"\d+"
0
Default, it's suppose to output true, but it's false
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?
0
https://code.sololearn.com/c41H5BJpXMxv/?ref=app
Does this print False for you if you don't give any input?
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
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.
0
đł. I don't see the difference, but the code you posted runs. Even after removing "-" mine does not
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.