Match Expression where a single special character in pattern can match one or more characters | Returns true if pat matches with text . ; i is used as an index in pattern and j as an index in text . ; Traverse through pattern ; If current character of pattern is not ' # ' ; If does not match with text . ; If matches , increment i and j ; Current character is ' # ' ; At least one character must match with # ; Match characters with # until a matching character is found . ; Matching with # is over , move ahead in pattern ; Driver code
function regexMatch ( text , pat ) { let lenText = text . length ; let lenPat = pat . length ; let Text = text . split ( " " ) ; let Pat = pat . split ( " " ) ; let i = 0 , j = 0 ; while ( i < lenPat ) { if ( Pat [ i ] != ' ' ) { if ( Pat [ i ] != Text [ j ] ) return false ; i ++ ; j ++ ; } else { j ++ ; while ( Text [ j ] != Pat [ i + 1 ] ) j ++ ; i ++ ; } } return ( j == lenText ) ; } let str = " " ; let pat = " " ; if ( regexMatch ( str , pat ) ) document . write ( " " ) ; else document . write ( " " ) ;