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?

Each of those characters is a or b, so they’re all matched. Are you wanting to only match one or the other?

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?

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


a or b then a or b then a or b then…

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.