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 Answers
+ 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]