This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function regEx(p, w, i, j) { | |
if( i == p.length && j == w.length ) | |
return true; | |
if ( j == w.length || i == p.length ) | |
return false; | |
//if second char is * | |
if ( i+1<p.length && p.charAt(i+1) == '*' ){ | |
//match pre char 0 time | |
if(regEx(p, w, i+2, j)) | |
return true; | |
//match pre char 1+ times | |
for(let k = j; k<w.length && (p.charAt(i)==w.charAt(k) || p.charAt(i) == '.'); k++) { | |
if(regEx(p, w, i+2, k+1)) | |
return true; | |
} | |
} | |
if(p.charAt(i) == w.charAt(j) || p.charAt(i) == '.') { | |
if(regEx(p, w, i+1, j+1)) | |
return true; | |
} | |
return false; | |
} |