# I can not understand why "ab" matches ".*"

• Does it mean that ".*" matches every input?

• Yes. '.' is any character, '*' means zero or more occurrences of previous character.

• But the test case says "ab" and ".*c" should be false

• because . * c means any string that ends with 'c'.
The string "ab" can match ". * " but it doesn't end with 'c', so the match is false.

• Thanks for the reply, but there is another test case "aab" and "c *a *b", it says it is true, how can this be possible?

• in the regular expression "c *a *b":
"c * " means there is 0 or 1 or multiple 'c'.
"a * " means there is 0 or 1 or multiple 'a'.
And the end of string must be 'b'

"aab" meet above criteria, doesn't it? There is 0 'c', 2 'a', and it ends with 'b'.
Hope it helps.

• Got it, thanks.

• really good explanation for the test case aab and cab

• i'm still confused..

for .* matching ab, let's say '.' gives 'a' then '*' gives 0 or more of its previous character which is 'a'.

how is ab matched?

• @leooo.l: the previous character is '.', not 'a'. For ., it means, ''. '.', '..', '...', '...', and any number of '.' So . can match any string.

• ha...that's right. thanks:-)

• Can you help me to explain the case: why "aaa" "ab''ac''a" is true?

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.