What's the difference among those groups? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

What's the difference among those groups?

In python. The metachracter of | means to match one of the characters in a pettern. so : (1|2|3|4|5) will check for one match of those chars. [1-6] will do the same in that range. [12345] I think this one will do the same. sorry, I'm just confused. Help me and sorry for the long spech lol.

1st Feb 2018, 3:04 PM
Tamer Helal
Tamer Helal - avatar
3 Answers
+ 2
Thanks for your answer, but it was a test for me to point out the inequivalent expression and the answer was [1-6] and I didn't understand why. more explanation needed here. Thanks in advance.
1st Feb 2018, 7:14 PM
Tamer Helal
Tamer Helal - avatar
+ 1
the only difference is that the first one (1|2|...|5) is in a capturing group which can be referenced later. besides that they are all the same
1st Feb 2018, 3:55 PM
Jeremy
Jeremy - avatar
+ 1
well [1-6] is the only one that includes the number 6. but thats all
1st Feb 2018, 7:21 PM
Jeremy
Jeremy - avatar