File tree Expand file tree Collapse file tree 1 file changed +9
-11
lines changed Expand file tree Collapse file tree 1 file changed +9
-11
lines changed Original file line number Diff line number Diff line change 32
32
* @return {boolean }
33
33
*/
34
34
var isMatch = function ( s , p ) {
35
- var result = s . match ( RegExp ( p ) ) ;
36
- return result ? result [ 0 ] === s : false ;
35
+ if ( p . length === 0 ) {
36
+ return ! s . length
37
+ }
38
+ let firstLetterMatched = s . length > 0 && ( s [ 0 ] === p [ 0 ] || p [ 0 ] === '.' )
39
+
40
+ if ( p [ 1 ] === '*' ) {
41
+ return isMatch ( s , p . substring ( 2 ) ) || ( firstLetterMatched && isMatch ( s . substring ( 1 ) , p ) )
42
+ }
43
+ return firstLetterMatched && isMatch ( s . substring ( 1 ) , p . substring ( 1 ) )
37
44
} ;
38
-
39
- // Test cases
40
- console . log ( isMatch ( 'aa' , 'a' ) ) ; // false
41
- console . log ( isMatch ( 'aa' , 'aa' ) ) ; // true
42
- console . log ( isMatch ( 'aaa' , 'aa' ) ) ; // false
43
- console . log ( isMatch ( 'aa' , 'a*' ) ) ; // true
44
- console . log ( isMatch ( 'aa' , '.*' ) ) ; // true
45
- console . log ( isMatch ( 'ab' , '.*' ) ) ; // true
46
- console . log ( isMatch ( 'aab' , 'c*a*b' ) ) ; // true
You can’t perform that action at this time.
0 commit comments