What is the difference between r"gr(a|e)y" and r"gr[ae]y" | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

What is the difference between r"gr(a|e)y" and r"gr[ae]y"

26th Jul 2016, 5:08 PM
Lunu'anaki
Lunu'anaki - avatar
2 Answers
+ 9
Semantically nothing, but the character class regex r"gr[ae]y" would likely be more efficient as it doesn't cache the back reference needed to return group(1).
26th Jul 2016, 5:14 PM
Jeremy Hanford
Jeremy Hanford  - avatar
0
perfect answer
10th Sep 2016, 4:45 PM
Sanjay Dora
Sanjay Dora - avatar