# How does + symbol works in regular expression?

What's the difference between $a^*+b^*$ and $(a+b)^*$?

I was going through this question. So according to the question-:

(a+b)* generates $$\in$$, a,b,ab,ba,aa,ba,...

whereas a*+b* generates $$\in$$, a,aa,aaa,b,bb,bbb etc.

Why can't a*+b* generate ab? What's stopping it from generating it? I feel like I am missing something fundamental. (Even if I take english meaning of word "OR", (a+b)* should generate same as a,aa,b,bb etc.)

If $$E$$ and $$F$$ are regular expressions then $$E+F$$ is also a regular expression that matches all words that are matched by at least one of $$E$$ and $$F$$.
In you case $$E=a^*$$, $$F=b^*$$, and $$E+F=a^*+b^*$$. The word $$ab$$ is not matched by $$a^*+b^*$$ since it is not matched by $$a^*$$ nor by $$b^*$$.
• a only matches $a$, b only matches $b$, a+b matches all and only the words in $\{ a, b\}$. (a+b)* matches any word consisting of the concatenation of any number (possibly $0$) of words in $\{ a, b\}$. Apr 17, 2022 at 10:04
• No. a matches only $a$ (it does not match $aa$, $aaa$, $\dots$), and b matches only $b$. Apr 17, 2022 at 11:58