Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit ab2a0ff

Browse files
committed
upd: 正则表达式
1 parent a218178 commit ab2a0ff

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

‎src/regularExpressionMatching.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/**
2+
* @param {string} s
3+
* @param {string} p
4+
* @return {boolean}
5+
*/
6+
var isMatch = function(s, p) {
7+
if (!p) {
8+
return !s;
9+
}
10+
11+
let firstMatch = !!s && !!~['.', s[0]].indexOf(p[0]);
12+
if (p[1] === '*') {
13+
return isMatch(s, p.substr(2)) || firstMatch && isMatch(s.substr(1), p);
14+
} else {
15+
return firstMatch && isMatch(s.substr(1), p.substr(1));
16+
}
17+
};

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /