Given Regular expression isMatch("ab", ".*") shouldn't it be false ?


  • 1
    M

    I don't really understand why the example here
    isMatch("ab", ".*") is true ?
    as per given definition:
    '.' -> matches any single character
    '*' -> matches 0+ of proceeding character right ?
    so by definition what I understand is ".*" => '.' picks any character and '*' repeats it's preceeding character 0+ times right ??
    so as per my understanding :

    • isMatch("ab",".*") - false

    • isMatch("bbb",".*") - true

    • isMatch("aaaaaaaa",".*") - true

    • isMatch("ccccccc",".*") - true

    Correct me if I'm missing anything here ?


  • 0
    G

    I have the same confusion, but it seems like they have an order for '' and '.' !!!
    Take a look at ".
    ", I could interpret it as '.....' right? I think they interpret '.*' this way. Sorry I forget whether RX in the real world has this kinda order.


  • 0
    G

    @guolei329

    • '.*'

  • 0
    S

    I pretty agree with you.
    and isMatch("ab".".*c") the answer if false;
    ???
    who can tell me... the difference between it


  • 0

    '*' Matches zero or more of the preceding element (in the regular expression, not actual string to be matched), so ".*" will match '.' 0+ times.


Log in to reply
 

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