0
A Bug?
WHY the following only outputs Match 2 not Match 1? import re pattern = r"[aeiou][rgp]" if re.search(pattern, "grey"): print("Match 1") if re.search(pattern, "qwertyuiop"): print("Match 2") if re.search(pattern, "rhythm myths"): print("Match 3") # Output: # Match 2
3 ответов
0
I figured out:
The first [aeiou] is matched than the 2nd [rgp].
In the case of "grey", after 'e' is matched to the first [aeiou], the character left is 'y', which does not match any of the [rgp].
I think in the case "qwertyuiop", 'e' is matched first [aeiou], and then 'r' immediately to the second [rgp].
0
pattern = r"[aeiou][rgp]"
You are searching for a vowel letter ('a', 'e', 'i', 'o' or 'u') followed by either 'r' or 'g' or 'p'.
And that is matched in "qwertyuiop" only (Match2), there is 'e' followed by 'r' and also 'o' followed by 'p'.
However in Match1, there is 'e' followed by 'y' which doesn't match the pattern
0
One or more repetitions of a non-vowel, a vowel and a non-vowel