Web Analytics Made Easy -
StatCounter What strings does this regex matches ? (a|b)* - CodingForum


No announcement yet.

What strings does this regex matches ? (a|b)*

  • Filter
  • Time
  • Show
Clear All
new posts

  • Other 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?

  • #2
    You said everything correctly: it means match a or b zero or more times. But that means match any occurrence of a or b, regardless of the context. If you want to find strings with at least one or multiple consecutive occurrences of a or b you need (a+|b+) (the brackets are optional).
    Stop solving problems you don’t yet have!