its correct in python rex? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

its correct in python rex?

pattern = r"[1-5][0-9]" if re.search(pattern,"100"): print("Match 1") it supposed Any two-digit number from 10 to 59, but it matches with 100, why?

13th Jul 2017, 11:56 AM
Angel Mauricio Antolin Rivas
Angel Mauricio Antolin Rivas - avatar
3 Answers
+ 2
Because search() method will seach inside the provided string... do instead: pattern = r"^[1-5]\d
#x27; \d is for digit (same as class [0-9]) ^ at start stand for start of string $ at end stand for end of string
13th Jul 2017, 12:26 PM
visph
visph - avatar
0
I think you need to specify that you are only looking for 2 digits. Something like: pattern = r"[1-5][0-9]
quot; That way your regex will know that and end of line is expected after the second digit. Also, I think something like this might work as well: pattern = r"]d\d
quot; - the "translation" would be : digit digit endOfLine
13th Jul 2017, 12:26 PM
Darius Cernea
Darius Cernea - avatar
0
Which regex would match "email@domain.com"?
14th Apr 2024, 12:03 PM
maryam mm