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
< ? php function regexMatch ( $ text , $ pat ) { $ lenText = strlen ( $ text ) ; $ letPat = strlen ( $ pat ) ; $ i = 0 ; $ j = 0 ; while ( $ i < $ letPat ) { 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 ) ; } $ str = " ABABABA " ; $ pat = " A # B # A " ; if ( regexMatch ( $ str , $ pat ) ) echo " yes " ; else echo " no " ; ? >