Regular Expression Matching Algorithm

Regular expressions are used in search engines, search and replace dialogs of word CPUs and text editors, in text processing utility such as sed and AWK and in lexical analysis. A regular expression (shortened as regex or regexp; also referred to as rational expression) is a sequence of characters that specify a search shape. Regular expressions originated in 1951, when mathematician Stephen Cole Kleene described regular languages use his mathematical notation named regular events. Other early implementations of shape matching include the SNOBOL language, which make not use regular expressions, but instead its own shape matching concepts. In the late 2010s, several company started to offer hardware, FPGA, GPU implementations of PCRE compatible regex engines that are faster compared to CPU implementations.
class Solution {
public:
    bool isMatch(const char *s, const char *p) {
        // Start typing your C/C++ solution below
        // DO NOT write int main() function   

        if (s == NULL || p == NULL) 
            return false;
        if (*p == '\0') 
            return  *s == '\0';
        
        if (*(p+1) == '*') {
            //
            // notice: ".*" means repeat '.' 0 or more times
            //
            while ((*s != '\0' && *p == '.') || *s == *p) {
                if (isMatch(s, p + 2))
                    return true;
                s += 1;
            }
            return isMatch(s, p + 2);
        } 
        else if ((*s != '\0' && *p == '.') || *s == *p) {
            return isMatch(s + 1, p + 1);
        }
        return false;
    }
};

LANGUAGE:

DARK MODE: