My understanding about ".*"


  • 0
    L

    Given by the example,

    "ab", "."*

    it's true.

    But I've got:

    *Input: "ab", ".c"

    Output: true

    Expected: false

    Do I misunderstand anything?
    Thx.

    ////////

    The truth is,

    I just confused combining this example,

    "aab", "cab" -> true**

    and * means zero or more,

    so c* can means "", "c","cc","ccc"...


  • 0
    S

    Both s and p need to be totally matched! not partially matched

    Input: "ab", ".c" should return false because "." can match "ab" but "c" have nothing to match.

    Input: "aab", "cab" should return false!


  • 0
    Q

    '. *' matches any number of any characters.
    For example, 'd. *f' matches any string start with d and end with f, like "deaf" "daaaaf" "df"


  • 0
    C
    This post is deleted!

  • 0
    C
    This post is deleted!

  • 0
    C

    About why "ab" and ".* " will return true:
    We know '* ' matches zero or more of the preceding element, so ".*" means we can have zero or more of the '.', so here we can have a string have two '.' like "..", it is obviously matches "ab".

    But when input are "ab" and ".*c", the matching can only cover the partial of input string, so it will return false.


  • 0
    Q

    For some reason my * is not showed on screen. I typed * and . , and the pattern is 'd*.f' I am kind of dismayed by the 01 vote.


  • 0
    Y

    basically ".*" can mean ""(empty), "."(one char) , ".."(two char) , "..."(three char), "............."(any char)
    it can match any string.


Log in to reply
 

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