0
I'm lost on how the out put doesn't include match 3 yet "g" is part of [a-z]
import re pattern=r"g" if re.match(pattern,"gggg") print("match1") if re.match(pattern,"g") print("match2") if re.match(pattern,[a-z]) print("match3")
6 ответов
+ 2
I am not very good with this topic.
This is just an example.
import re
pattern = r"[a-z]"
if re.search(pattern,"g"):
print("yes")
+ 6
To explain further what Benjamin Jürgens has said, the format for re.match (and re.search) methods is re.match(regex_pattern, string). So
re.match(“[a-z]”, “g”) will return True, but
re.match(“g”, “[a-z]”) will return False.
The second one is looking for the char “g” at the start of the string “[a-z]”, which is clearly not there.
+ 3
"g" is not in "[a-z]"
But "g" is in "abcdefgh..."
You have to write out the alphabet, you can use regex syntax only for pattern
+ 2
It is clearly mentioned in the course.
"the re.match function can be used to determine whether it matches at the beginning of a string."
+ 1
Thank you so much
0
Ohhhhh...so in a code like that what would I use to prove that g is in [a-z]