4 ms·
What strings does this regex matches? (a|b)
regepxal is showing infinite matches and shows "baaaaaaa" as a match. Doesn't (a|b) means a or b?
* means match 0 or more times. So, it should be matching aa,aaa,bb,bbb, , etc?
I'm not getting how baaaa is a match. Can anyone clarify please?
- nhgiang 4y ago(b)(aaa...) Each char can be an a or b, then repeat, not "a repeating seq of either a or b only" (a|b)* = X* = x1x2x3... where each xi can be "a" or "b"
- shivajikobardan 4y agothis cleared my confusion. Thank you
- layer8 4y agoEach repetition can take a different path through the repeated expression. You don’t choose a value for the inner expression once and then repeat it; rather, each time you repeat you can select a value anew for the inner expression. PS: This question would be more appropriate on stackoverflow.
- compressedgas 4y agoYou want: (a*)|(b*) The strings of at most 3 that this matches are: e, a, aa, aaa, b, bb, bbb It appears that you have: (a|b)* The strings of at most 3 that this matches are: e, a, b, aa, ab, ba, bb, aaa, aab, aba, abb, baa, bab, bba, bbb Where e is the empty string
- shivajikobardan 4y agoOP Updates: I feel I'm not getting it. I feel I'm missing something that you have good grasp of. You choose a or b and repeat, so aaaa, bbbb should be only matches. Could you help me out?
- bediger4000 4y ago/(a|b)/ does mean roughly "a string with an 'a' or a 'b' in it". So /(a|b)/ should have "baaaaaa" as a match. The string has an 'a'. The string has a 'b'. It matches.
- shivajikobardan 4y agoits (a|b)*
- shivajikobardan 4y agoOP updates: Thank you. The perfect way to think about this for me is this: (X)*= X X X X X X Here X=a or b So, a or b then a or b then a or b then....