+ 1
why it doesnt match next
in this example: import re pattern = r"^gr.y
quot; if re.match(pattern, "grey"): print("Match 1") if re.match(pattern, "gray"): print("Match 2") if re.match(pattern, "stingray"): print("Match 3") if re.match(pattern, "grstingray"): if the string starts with gr. Its the third "if sentence"" why it doesn't match with the regular expression : r"^gr.yquot; ?6 ответов
+ 1
@Angel, can you post your code please? I don't understand your question, sorry xD
+ 1
Your RegEx means :
first character : g
second character : r
third character : anything
fourth and last character : y
So stingray has more than 4 character like grstingray
+ 1
Baptiste E. Prunier. Thank you so much. I undertood that . could be any number of characters but its just one,
0
Yes that's it ! You're welcome :)
0
so
import re
pattern = r"^gr..yquot;
if re.match(pattern, "greey"):
print("Match 1")
if re.match(pattern, "gray"):
print("Match 2")
if re.match(pattern, "gramystingray"):
print("Match 3")
if re.match(pattern, "gramy"):
print("Match 4")
result:
Match 1
Match 4
0
Yes because it needs exactly 2 characters between r and y